以下存储过程有效。但是,它不会在SQL Reporting Services报告(SSRS报告)中显示数据。
它必须是不显示数据的临时表。
如何获取SSRS报告来提取数据?
原始存储过程是当前存储过程的上半部分。
我们通过复制"从上到下修改了存储过程"并将代码添加到上半部分的选择语句"其中"条款库存项目编号(ITEMNMBR),以“" CUSTOM"或" SPECIAL"。
我们希望存储过程的两半都运行 - 循环或没有循环 - 在某种意义上,如果项目是" CUSTOM"或" SPECIAL",然后运行存储过程的上半部分。如果项目编号不是这些,则运行底部。
它类似于" if-then"言。
首先,我尝试插入一个" UNION ALL"介于两者之间。但是,SQL给了我一个语法错误,直到我删除它。
请让我知道你的想法。
谢谢!
约翰
ALTER procedure [dbo].[SRS_TransferBackOrdersToWareHouseBatch]
as
declare @sourceBatchRecordCount int
declare @destBatchRecordCount int
declare @destBatch varchar(30)
declare @sourceBatch varchar(30)
set @sourceBatch = 'BACKORDER'
set @destBatch = 'WAREHOUSE'
select @sourceBatchRecordCount = COUNT(*) from SOP10100 where bachnumb = @sourceBatch
select @destBatchRecordCount = COUNT(*) from SOP10100 where BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
(ITEMNMBR LIKE '%CUSTOM' AND
ATYALLOC > 0) OR (ITEMNMBR LIKE '%SPECIAL' AND
ATYALLOC > 0))
select sopnumbe into #movedBO from SOP10100 where BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
(ITEMNMBR LIKE '%CUSTOM' AND
ATYALLOC > 0) OR (ITEMNMBR LIKE '%SPECIAL' AND
ATYALLOC > 0))
--print @sourceBatchRecordCount
--print @destBatchRecordCount
if @destBatchRecordCount > 0
begin
declare @p30 int
set @p30=0
declare @p31 varchar(255)
set @p31=''
exec taCreateUpdateBatchHeaderRcd @I_vBACHNUMB=@destBatch,@I_vBCHCOMNT=default,@I_vSERIES=3,@I_vGLPOSTDT=default,@I_vBCHSOURC='Sales Entry ',
@I_vDOCAMT=0,@I_vORIGIN=1,@I_vNUMOFTRX=0,@I_vCHEKBKID=default,@I_vCNTRLTOT=default,@I_vCNTRLTRX=default,@I_vPOSTTOGL=0,@I_vPmtMethod=default,
@I_vEFTFileFormat=default,@I_vRequesterTrx=default,@I_vBRKDNALL=default,@I_vUSERID=default,@I_vBACHFREQ=default,@I_vRECPSTGS=default,
@I_vMSCBDINC=default,@I_vAPPROVL=default,@I_vAPPRVLDT=default,@I_vAPRVLUSERID=default,@I_vTRXSOURC=default,@I_vUSRDEFND1=default,
@I_vUSRDEFND2=default,@I_vUSRDEFND3=default,@I_vUSRDEFND4=default,@I_vUSRDEFND5=default,@O_iErrorState=@p30 output,@oErrString=@p31 output
--EMOIS 9/2/2105 Change update to single update statement for each row, this will cause trigger to fire correctly
DECLARE @sopNumber CHAR(21)
DECLARE updateSOP CURSOR FOR
SELECT RTRIM(SOPNUMBE) FROM SOP10100 WHERE BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
(ITEMNMBR LIKE '%CUSTOM' AND
ATYALLOC > 0) OR (ITEMNMBR LIKE '%SPECIAL' AND
ATYALLOC > 0))
OPEN updateSOP FETCH NEXT FROM updateSOP INTO @sopNumber
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE SOP10100
SET BACHNUMB = @destBatch --ReqShipDate = CONVERT(date, getDate()) Removed to keep original ReqShipDate
FROM SOP10100 WHERE SOPNUMBE = @sopNumber
FETCH NEXT FROM updateSOP INTO @sopNumber
END
CLOSE updateSOP DEALLOCATE updateSOP
select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO
-- reconcile batch headers
set nocount on
DECLARE @bachnumb char(25)
, @numtrx int
, @batchamount numeric(19,5)
DECLARE c_sop CURSOR FOR
SELECT rtrim(BACHNUMB) FROM SY00500 WHERE (SERIES = 3) AND (BCHSOURC = 'Sales Entry') order by 1
OPEN c_sop FETCH NEXT FROM c_sop INTO @bachnumb
WHILE @@FETCH_STATUS = 0
BEGIN SELECT @numtrx = ISNULL(COUNT(SOPNUMBE),0)
, @batchamount = ISNULL(SUM(DOCAMNT),0)
FROM SOP10100 WHERE BACHNUMB = @bachnumb
UPDATE SY00500 SET NUMOFTRX = @numtrx, BCHTOTAL = @batchamount WHERE BACHNUMB = @bachnumb
--Print rtrim(@bachnumb) +' ,Transactions = '+COnvert(varchar(100),@numtrx) +' ,BatchTotal = '+COnvert(varchar(100),@batchamount)
FETCH NEXT FROM c_sop INTO @bachnumb
END
CLOSE c_sop DEALLOCATE c_sop
end
else
select 'No documents.' as 'BackOrderNo'
--declare @sourceBatchRecordCount int
--declare @destBatchRecordCount int
--declare @destBatch varchar(30)
--declare @sourceBatch varchar(30)
--set @sourceBatch = 'BACKORDER'
--set @destBatch = 'WAREHOUSE'
select @sourceBatchRecordCount = COUNT(*) from SOP10100 where bachnumb = @sourceBatch
select @destBatchRecordCount = COUNT(*) from SOP10100 where BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
ATYALLOC > 0)
select sopnumbe into #movedBO2 from SOP10100 where BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
ATYALLOC > 0)
--print @sourceBatchRecordCount
--print @destBatchRecordCount
if @destBatchRecordCount > 0
begin
set @p30=0
set @p31=''
exec taCreateUpdateBatchHeaderRcd @I_vBACHNUMB=@destBatch,@I_vBCHCOMNT=default,@I_vSERIES=3,@I_vGLPOSTDT=default,@I_vBCHSOURC='Sales Entry ',
@I_vDOCAMT=0,@I_vORIGIN=1,@I_vNUMOFTRX=0,@I_vCHEKBKID=default,@I_vCNTRLTOT=default,@I_vCNTRLTRX=default,@I_vPOSTTOGL=0,@I_vPmtMethod=default,
@I_vEFTFileFormat=default,@I_vRequesterTrx=default,@I_vBRKDNALL=default,@I_vUSERID=default,@I_vBACHFREQ=default,@I_vRECPSTGS=default,
@I_vMSCBDINC=default,@I_vAPPROVL=default,@I_vAPPRVLDT=default,@I_vAPRVLUSERID=default,@I_vTRXSOURC=default,@I_vUSRDEFND1=default,
@I_vUSRDEFND2=default,@I_vUSRDEFND3=default,@I_vUSRDEFND4=default,@I_vUSRDEFND5=default,@O_iErrorState=@p30 output,@oErrString=@p31 output
--EMOIS 9/2/2105 Change update to single update statement for each row, this will cause trigger to fire correctly
DECLARE updateSOP CURSOR FOR
SELECT RTRIM(SOPNUMBE) FROM SOP10100 WHERE BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
ATYALLOC > 0)
OPEN updateSOP FETCH NEXT FROM updateSOP INTO @sopNumber
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE SOP10100
SET BACHNUMB = @destBatch, ReqShipDate = getDate() --Removed to keep original ReqShipDate
FROM SOP10100 WHERE SOPNUMBE = @sopNumber
--UPDATE SOP10100 SET ReqShipDate = CONVERT(date, getDate())
-- FROM SOP10100 WHERE SOPNUMBE = @sopNumber
FETCH NEXT FROM updateSOP INTO @sopNumber
END
CLOSE updateSOP DEALLOCATE updateSOP
select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO
-- reconcile batch headers
set nocount on
DECLARE c_sop CURSOR FOR
SELECT rtrim(BACHNUMB) FROM SY00500 WHERE (SERIES = 3) AND (BCHSOURC = 'Sales Entry') order by 1
OPEN c_sop FETCH NEXT FROM c_sop INTO @bachnumb
WHILE @@FETCH_STATUS = 0
BEGIN SELECT @numtrx = ISNULL(COUNT(SOPNUMBE),0)
, @batchamount = ISNULL(SUM(DOCAMNT),0)
FROM SOP10100 WHERE BACHNUMB = @bachnumb
UPDATE SY00500 SET NUMOFTRX = @numtrx, BCHTOTAL = @batchamount WHERE BACHNUMB = @bachnumb
--Print rtrim(@bachnumb) +' ,Transactions = '+COnvert(varchar(100),@numtrx) +' ,BatchTotal = '+COnvert(varchar(100),@batchamount)
FETCH NEXT FROM c_sop INTO @bachnumb
END
CLOSE c_sop DEALLOCATE c_sop
end
else
select 'No documents.' as 'BackOrderNo'
答案 0 :(得分:0)
如果您希望将此存储过程与SSRS报告一起使用,那么您将不得不更改某些内容以使其正常工作。你有一些选择。
第一个选项:将存储过程分解为2个存储过程。 SSRS报告可以有多个数据集。有一个用于原始程序,另一个用于新部分。您最终会在报告中找到2个数据表,但最终用户可能会对此感到满意。
第二个选项:将过程中的select语句移动到代码的末尾并在那里进行联合。你曾提到尝试类似的东西,但如果我理解你所描述的内容,它就不会有效。
select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO
UNION ALL
select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO2 -- See BTW below
然后,通过检查返回的记录数并在文本框中显示/隐藏该消息来处理RDL中的“无文档”部分。您也可以根据行数显示/隐藏表格。您可以在控件的隐藏属性中使用以下表达式。
=IIf(CountRows("DataSet1") > 0, False, True) ' Show me
=IIf(CountRows("DataSet1") = 0, True, False) ' Hide me
顺便说一句,你在程序中创建了一个名为#movedBO2
的表,但是你以后再也不会从中选择它。所以,仔细检查代码。
修改强>
更新了存储过程:
CREATE PROCEDURE [dbo].[SRS_TransferBackOrdersToWareHouseBatch]
as
declare @sourceBatchRecordCount int
declare @destBatchRecordCount int
declare @destBatch varchar(30)
declare @sourceBatch varchar(30)
set @sourceBatch = 'BACKORDER'
set @destBatch = 'WAREHOUSE'
select @sourceBatchRecordCount = COUNT(*) from SOP10100 where bachnumb = @sourceBatch
select @destBatchRecordCount = COUNT(*) from SOP10100 where BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
(ITEMNMBR LIKE '%CUSTOM' AND
ATYALLOC > 0) OR (ITEMNMBR LIKE '%SPECIAL' AND
ATYALLOC > 0))
select sopnumbe into #movedBO from SOP10100 where BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
(ITEMNMBR LIKE '%CUSTOM' AND
ATYALLOC > 0) OR (ITEMNMBR LIKE '%SPECIAL' AND
ATYALLOC > 0))
if @destBatchRecordCount > 0
begin
declare @p30 int
set @p30=0
declare @p31 varchar(255)
set @p31=''
exec taCreateUpdateBatchHeaderRcd @I_vBACHNUMB=@destBatch,@I_vBCHCOMNT=default,@I_vSERIES=3,@I_vGLPOSTDT=default,@I_vBCHSOURC='Sales Entry ',
@I_vDOCAMT=0,@I_vORIGIN=1,@I_vNUMOFTRX=0,@I_vCHEKBKID=default,@I_vCNTRLTOT=default,@I_vCNTRLTRX=default,@I_vPOSTTOGL=0,@I_vPmtMethod=default,
@I_vEFTFileFormat=default,@I_vRequesterTrx=default,@I_vBRKDNALL=default,@I_vUSERID=default,@I_vBACHFREQ=default,@I_vRECPSTGS=default,
@I_vMSCBDINC=default,@I_vAPPROVL=default,@I_vAPPRVLDT=default,@I_vAPRVLUSERID=default,@I_vTRXSOURC=default,@I_vUSRDEFND1=default,
@I_vUSRDEFND2=default,@I_vUSRDEFND3=default,@I_vUSRDEFND4=default,@I_vUSRDEFND5=default,@O_iErrorState=@p30 output,@oErrString=@p31 output
--EMOIS 9/2/2105 Change update to single update statement for each row, this will cause trigger to fire correctly
DECLARE @sopNumber CHAR(21)
DECLARE updateSOP CURSOR FOR
SELECT RTRIM(SOPNUMBE) FROM SOP10100 WHERE BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where
(ITEMNMBR LIKE '%CUSTOM' AND
ATYALLOC > 0) OR (ITEMNMBR LIKE '%SPECIAL' AND
ATYALLOC > 0))
OPEN updateSOP FETCH NEXT FROM updateSOP INTO @sopNumber
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE SOP10100
SET BACHNUMB = @destBatch --ReqShipDate = CONVERT(date, getDate()) Removed to keep original ReqShipDate
FROM SOP10100 WHERE SOPNUMBE = @sopNumber
FETCH NEXT FROM updateSOP INTO @sopNumber
END
CLOSE updateSOP DEALLOCATE updateSOP
-- select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO
-- reconcile batch headers
set nocount on
DECLARE @bachnumb char(25)
, @numtrx int
, @batchamount numeric(19,5)
DECLARE c_sop CURSOR FOR
SELECT rtrim(BACHNUMB) FROM SY00500 WHERE (SERIES = 3) AND (BCHSOURC = 'Sales Entry') order by 1
OPEN c_sop FETCH NEXT FROM c_sop INTO @bachnumb
WHILE @@FETCH_STATUS = 0
BEGIN SELECT @numtrx = ISNULL(COUNT(SOPNUMBE),0)
, @batchamount = ISNULL(SUM(DOCAMNT),0)
FROM SOP10100 WHERE BACHNUMB = @bachnumb
UPDATE SY00500 SET NUMOFTRX = @numtrx, BCHTOTAL = @batchamount WHERE BACHNUMB = @bachnumb
--Print rtrim(@bachnumb) +' ,Transactions = '+COnvert(varchar(100),@numtrx) +' ,BatchTotal = '+COnvert(varchar(100),@batchamount)
FETCH NEXT FROM c_sop INTO @bachnumb
END
CLOSE c_sop DEALLOCATE c_sop
end
select @sourceBatchRecordCount = COUNT(*) from SOP10100 where bachnumb = @sourceBatch
select @destBatchRecordCount = COUNT(*) from SOP10100 where BACHNUMB = @sourceBatch
and SOPNUMBE in (select SOPNUMBE from SOP10200 where ATYALLOC > 0)
select sopnumbe into #movedBO2 from SOP10100 where BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where ATYALLOC > 0)
if @destBatchRecordCount > 0
begin
set @p30=0
set @p31=''
exec taCreateUpdateBatchHeaderRcd @I_vBACHNUMB=@destBatch,@I_vBCHCOMNT=default,@I_vSERIES=3,@I_vGLPOSTDT=default,@I_vBCHSOURC='Sales Entry ',
@I_vDOCAMT=0,@I_vORIGIN=1,@I_vNUMOFTRX=0,@I_vCHEKBKID=default,@I_vCNTRLTOT=default,@I_vCNTRLTRX=default,@I_vPOSTTOGL=0,@I_vPmtMethod=default,
@I_vEFTFileFormat=default,@I_vRequesterTrx=default,@I_vBRKDNALL=default,@I_vUSERID=default,@I_vBACHFREQ=default,@I_vRECPSTGS=default,
@I_vMSCBDINC=default,@I_vAPPROVL=default,@I_vAPPRVLDT=default,@I_vAPRVLUSERID=default,@I_vTRXSOURC=default,@I_vUSRDEFND1=default,
@I_vUSRDEFND2=default,@I_vUSRDEFND3=default,@I_vUSRDEFND4=default,@I_vUSRDEFND5=default,@O_iErrorState=@p30 output,@oErrString=@p31 output
--EMOIS 9/2/2105 Change update to single update statement for each row, this will cause trigger to fire correctly
DECLARE updateSOP CURSOR FOR
SELECT RTRIM(SOPNUMBE) FROM SOP10100 WHERE BACHNUMB = @sourceBatch and SOPNUMBE in (select SOPNUMBE from SOP10200 where ATYALLOC > 0)
OPEN updateSOP FETCH NEXT FROM updateSOP INTO @sopNumber
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE SOP10100
SET BACHNUMB = @destBatch, ReqShipDate = getDate() --Removed to keep original ReqShipDate
FROM SOP10100 WHERE SOPNUMBE = @sopNumber
--UPDATE SOP10100 SET ReqShipDate = CONVERT(date, getDate())
-- FROM SOP10100 WHERE SOPNUMBE = @sopNumber
FETCH NEXT FROM updateSOP INTO @sopNumber
END
CLOSE updateSOP DEALLOCATE updateSOP
-- select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO2
-- reconcile batch headers
set nocount on
DECLARE c_sop CURSOR FOR
SELECT rtrim(BACHNUMB) FROM SY00500 WHERE (SERIES = 3) AND (BCHSOURC = 'Sales Entry') order by 1
OPEN c_sop FETCH NEXT FROM c_sop INTO @bachnumb
WHILE @@FETCH_STATUS = 0
BEGIN SELECT @numtrx = ISNULL(COUNT(SOPNUMBE),0)
, @batchamount = ISNULL(SUM(DOCAMNT),0)
FROM SOP10100 WHERE BACHNUMB = @bachnumb
UPDATE SY00500 SET NUMOFTRX = @numtrx, BCHTOTAL = @batchamount WHERE BACHNUMB = @bachnumb
--Print rtrim(@bachnumb) +' ,Transactions = '+COnvert(varchar(100),@numtrx) +' ,BatchTotal = '+COnvert(varchar(100),@batchamount)
FETCH NEXT FROM c_sop INTO @bachnumb
END
CLOSE c_sop DEALLOCATE c_sop
end
SELECT RTRIM(sopnumbe) AS 'BackOrderNo'
INTO #movedBO3
FROM #movedBO
UNION ALL
SELECT RTRIM(sopnumbe) AS 'BackOrderNo'
FROM #movedBO2
IF EXISTS (SELECT * FROM #movedBO3)
SELECT * FROM #movedBO3
ELSE
select 'No documents.' as 'BackOrderNo'
DROP TABLE #movedBO
DROP TABLE #movedBO2
DROP TABLE #movedBO3
这应该有效。由于我没有你的数据,我不能肯定你不会有问题,但这应该让你知道如何做到这一点。 RDL(报告)不应该改变,我不认为。
希望这有帮助!