简体   繁体   English

SSRS报告的ALL参数

[英]ALL parameter for SSRS Report

I want to be able to let the business manually enter a USERID into a parameter box or leave it blank for it to bring back all USERID's. 我希望能够让企业手动在参数框中输入USERID或将其保留为空白以带回所有USERID。

I have setup another parameter for CUSTOMERID which uses a dataset to bring back a list of customer ID's. 我为CUSTOMERID设置了另一个参数,该参数使用数据集带回客户ID的列表。 Due to the amount of USERID's I don't want to use the same solution but instead have them manually enter the USERID or leave it blank and bring back ALL. 由于USERID的数量,我不想使用相同的解决方案,而是让他们手动输入USERID或将其保留为空白,然后全部取回。

SELECT 
    CUSTOMERID,
    CASE 
    WHEN STATUSCODE = 200 THEN 'Successful Logon' 
    ELSE 'Unsuccessful Logon' 
    END as LogonStatus,
    COUNT( * ) COUNTOFACCOUNTS

FROM 
    MA4EQNG.APPLICATIONLOG
WHERE 
    CUSTOMERID in ('"+join(Parameters!CustomerID.Value, "','")+"')
    AND (Cast(DATETIME as Date) >= '"& Format(Parameters!FromDate.Value, "yyyy-MM-dd") & "' 
    AND Cast(DATETIME as Date) <= '" & Format(Parameters!ToDate.Value, "yyyy-MM-dd") & "') 
    AND COMPONENTDESCRIPTION = '/eq/auth/v1/logon'
    AND METHOD = 'POST' 

GROUP BY 
    CUSTOMERID,
    CASE 
        WHEN STATUSCODE = 200 THEN 'Successful Logon' 
        ELSE 'Unsuccessful Logon' 
    END

ORDER BY
CUSTOMERID ASC

Please let me know if you need anything else. 如果您还有其他需要,请告诉我。

You can set the USERID parameter to allow blank value then use IF condition on your main dataset sql script. 您可以将USERID参数设置为允许空白值,然后在主数据集sql脚本上使用IF条件。

Try 尝试

IF LEN(@USERID)>0
*put the sql script with UserId filter in where clause*
ELSE
*put the sql script WITHOUT UserId filter in where clause*

Normally you would just script something like this in the WHERE clause. 通常,您只需要在WHERE子句中编写这样的脚本即可。

WHERE isnull(@CustomerID,'') = '' OR (CUSTOMERID in('"+join(Parameters!CustomerID.Value, "','")+"')) WHERE notull(@CustomerID,'')=''或(CUSTOMERID in('“ + join(Parameters!CustomerID.Value,”','“)+”'))

And long term, I would create a function that takes in a delimited string, and converts them to rows, then you can just join on the results from the table valued function. 从长远来看,我将创建一个使用带分隔符的字符串并将其转换为行的函数,然后就可以对表值函数的结果进行联接。

How to split a comma-separated value to columns 如何将逗号分隔的值拆分为列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM