s-s-rS 报告未从存储过程中提取数据
Posted
技术标签:
【中文标题】s-s-rS 报告未从存储过程中提取数据【英文标题】:s-s-rS Report Not Pulling Data from Stored Procedure 【发布时间】:2017-04-15 23:03:12 【问题描述】:下面的存储过程有效。但是,它不会在 SQL Reporting Services 报告(s-s-rS 报告)中显示数据。
它必须是一个不显示数据的临时表。
如何获取 s-s-rS 报告以提取数据?
原始存储过程是当前存储过程的上半部分。
我们通过复制“从上到下”并将代码添加到上半部分的 select 语句的“where”子句来修改存储过程,以说明以单词“CUSTOM”或“SPECIAL”结尾的库存项目编号 (ITEMNMBR) .
我们希望存储过程的两半都运行——循环或不循环——在某种意义上,如果项目是“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'
【问题讨论】:
【参考方案1】:如果您想将此存储过程与 s-s-rS 报告一起使用,那么您将不得不更改一些内容才能使其正常工作。你有一些选择。
第一个选项:将存储过程分解为 2 个存储过程。 s-s-rS 报告可以有多个数据集。有一个用于原始程序,另一个用于新部分。您最终会在报告中得到 2 个数据表,但最终用户可能会接受。
第二个选项:将过程中的选择语句移动到代码的末尾并在那里进行联合。你提到尝试这样的事情,但如果我正确理解你的描述,它就不会奏效。
select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO
UNION ALL
select rtrim(sopnumbe) as 'BackOrderNo' from #movedBO2 -- See BTW below
然后,通过检查返回的记录数并在文本框中显示/隐藏该消息来处理 RDL 中的“无文档”部分。您也可以根据行数显示/隐藏表格。您可以在控件的 Hidden 属性中使用以下表达式。
=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(报告)不应该改变,我不认为。
希望这会有所帮助!
【讨论】:
感谢您的快速回复,Richards 先生!你提到我没有从#movedBO2中选择,“稍后”。我在以下语句中这样做:从#movedBO2 中选择 rtrim(sopnumbe) 作为 'BackOrderNo'。你能澄清一下你的意思吗? :) 嗨,理查兹先生:您说得对!我认为,当我第一次将代码“粘贴”到这篇文章中时,我很难过,它不小心切断了最后几行。非常感谢,对于造成的混乱,我深表歉意!我希望明天试试你的步骤。我会让你知道情况如何。 :) 约翰 你好:我得到了代码工作。但是,该报告没有显示两个“部分”。我使用了上面的两个 IIF 语句。有任何想法吗?约翰 “碎片”?你能简单解释一下吗?您如何/在哪里使用IIF
?
有两半--临时表#movedBO和#movedBO2。以上是关于s-s-rS 报告未从存储过程中提取数据的主要内容,如果未能解决你的问题,请参考以下文章
s-s-rs 报告在浏览器上显示空白 2997 行数据,存储过程时间为 42 秒