今天,在使用 SSRS 时,我遇到了一个惊人的问题。我仍然无法找出问题所在。好吧,我有一个存储过程:
ALTER PROCEDURE [dbo].[S_MEMBER_DROP_OUT_REPORT](@DTNAME VARCHAR(50),
@BRCODE VARCHAR(3),
@F_DATE VARCHAR(10),
@T_DATE VARCHAR(10),
@CLOSECODE VARCHAR(50),
@CENTRALIZED VARCHAR(3))
WITH RECOMPILE
AS BEGIN
SET NOCOUNT ON;
DECLARE @DTBASE VARCHAR(50)
DECLARE @CLOSEOPT VARCHAR(50)
SET @DTBASE=''
IF @CENTRALIZED='YES'
SET @DTBASE = @DTNAME
ELSE
SET @DTBASE = Left(@DTNAME, 13) + @BRCODE
IF @CLOSECODE ='0'
BEGIN
Exec ('
SELECT T1.CENTER_CODE + '' - '' + CTR.CENTER_NAME AS CENTER,COUNT(DISTINCT T1.CUSTOMER_CODE) AS CNT
FROM
(SELECT * FROM CENTER W WHERE BR_CODE='''+@BRCODE+''') AS CTR,
(SELECT A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE,MAX(A2.CLOSE_DATE) AS REDG_DATE,MAX(A2.TRAN_ID) AS TRAN_ID FROM '+@DTBASE+'.dbo.CENTER_GROUP_MEMBER AS A1, '+@DTBASE+'.dbo.CUST_REDG_HIST A2,'+@DTBASE+'.dbo.CUST_STATUS_HIST A3
WHERE A2.CUST_STATUS_CODE=''04'' AND A2.CLOSE_CODE<>''03''
AND A1.BR_CODE='''+@BRCODE+''' AND A2.BR_CODE='''+@BRCODE+'''
AND (A2.CLOSE_DATE BETWEEN '''+@F_DATE+''' AND '''+@T_DATE+''')
AND A1.CUSTOMER_CODE=A2.CUSTOMER_CODE
AND A1.CUSTOMER_CODE=A3.CUSTOMER_CODE AND A1.CENTER_CODE=A3.CENTER_CODE AND A1.GROUP_CODE=A3.GROUP_CODE
AND A3.TRAN_ID=(SELECT TOP 1 TRAN_ID FROM '+@DTBASE+'.dbo.CUST_STATUS_HIST CSH WHERE A3.CUSTOMER_CODE=CSH.CUSTOMER_CODE ORDER BY TRAN_ID DESC)
GROUP BY A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE
) AS T1
WHERE T1.CENTER_CODE=CTR.CENTER_CODE
GROUP BY T1.CENTER_CODE,CTR.CENTER_NAME
ORDER BY T1.CENTER_CODE
')
END
ELSE
BEGIN
IF LEN(@CLOSECODE) > 0 SET @CLOSEOPT=' AND A2.CLOSE_CODE IN ('+@CLOSECODE+')' ELSE SET @CLOSEOPT=''
Exec ('
SELECT T1.CENTER_CODE + '' - '' + CTR.CENTER_NAME AS CENTER,CCC.CLOSE_NAME,CCD.CLOSE_DESC_NAME AS CLOSE_DESC,COUNT(DISTINCT T1.CUSTOMER_CODE) AS CNT FROM
(SELECT * FROM '+@DTBASE+'.dbo.CUST_CLOSE_CAUSE) AS CCC,
(SELECT * FROM '+@DTBASE+'.dbo.CUST_CLOSE_DESC) AS CCD,
(SELECT * FROM CENTER WHERE BR_CODE='''+@BRCODE+''') AS CTR,
(SELECT A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE,MAX(A2.CLOSE_DATE) AS REDG_DATE,MAX(A2.TRAN_ID) AS TRAN_ID FROM '+@DTBASE+'.dbo.CENTER_GROUP_MEMBER AS A1,'+@DTBASE+'.dbo.CUST_REDG_HIST A2,'+@DTBASE+'.dbo.CUST_STATUS_HIST A3
WHERE A2.CUST_STATUS_CODE=''04'' '+@CLOSEOPT+'
AND A1.BR_CODE='''+@BRCODE+''' AND A2.BR_CODE='''+@BRCODE+'''
AND (A2.CLOSE_DATE BETWEEN '''+@F_DATE+''' AND '''+@T_DATE+''')
AND A1.CUSTOMER_CODE=A2.CUSTOMER_CODE
AND A1.CUSTOMER_CODE=A3.CUSTOMER_CODE AND A1.CENTER_CODE=A3.CENTER_CODE AND A1.GROUP_CODE=A3.GROUP_CODE
AND A3.TRAN_ID=(SELECT TOP 1 TRAN_ID FROM '+@DTBASE+'.dbo.CUST_STATUS_HIST CSH WHERE A3.CUSTOMER_CODE=CSH.CUSTOMER_CODE ORDER BY TRAN_ID DESC)
GROUP BY A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE
) AS T1
WHERE T1.CLOSE_DESC_CODE =CCD.CLOSE_DESC_CODE
AND T1.CLOSE_CODE =CCC.CLOSE_CODE
AND T1.CENTER_CODE=CTR.CENTER_CODE
GROUP BY T1.CENTER_CODE,CCD.CLOSE_DESC_NAME,CCC.CLOSE_NAME,CTR.CENTER_NAME
')
END
END
GO
上面的存储过程要求一个 Parameter Named CLOSECODE
,并根据提供的值,例如“0”或“01”或“02”,它从相应的表中返回所需的字段。返回的字段因该参数而异。
当我在 SSRS 中定义数据集时,如下所示:
它不要求任何参数值,默认情况下会生成以下字段:
我尝试了所有出现在我脑海中的问题,即问题所在。但仍然无法解决这个问题。而且,实际上,我想知道,为什么 SSRS 今天会这样。自从 2-3 个月以来,我一直在使用它,到目前为止,我已经设计了很多这样的报告,其中包含动态查询、存储过程中的字段,但没有任何问题,但是这个。