简体   繁体   English

ssrs用户在参数中键入多个值或将其留空

[英]ssrs user typing in multiple values in a parameter or leaving it blank

I am creating a report in SSRS and have a parameter for the end users to search for an account number. 我正在SSRS中创建一个报告,并为最终用户提供一个参数来搜索帐号。 Within the report the parameter is set to null by default to show all accounts. 在报告中,默认情况下参数设置为null以显示所有帐户。 When the parameter is not null the user should be able to type in a single account or multiple accounts separated by commas. 当参数不为null时,用户应该能够键入单个帐户或用逗号分隔的多个帐户。 My problem is when I try to type in multiple accounts I get this error: 我的问题是,当我尝试输入多个帐户时,我收到此错误:

"An expression of non-boolean type specified in a context where a condition is expected, near ','." “在预期条件的上下文中指定的非布尔类型的表达式,靠近','。”

Here is my sql query: 这是我的SQL查询:

SELECT * FROM test_db WHERE (AccountNumber IN (@Account)) OR (@Account IS NULL)

The code on the parameter for @Account is @Account参数的代码是

=IIF(IsNothing(Parameters!Account.Value),Parameters!Account.Value,Split(Parameters!Account.Value,","))

You don't need to do anything with it. 你不需要做任何事情。 If you make the @Account parameter multi-value, you can simply type each entry followed by [Enter], no commas, just your required value, one on each row of the parameter drop down. 如果将@Account参数设置为多值,则只需键入每个条目,然后按[Enter],不使用逗号,只输入所需的值,在参数下拉列的每一行上输入一个。

在此输入图像描述

Then your original query will work, SSRS will automatically convert the multi-value list into a comma separated list and inject it into your SQL. 然后您的原始查询将起作用,SSRS将自动将多值列表转换为逗号分隔列表并将其注入您的SQL。 If this doesn't make sense, let me know and I'll put a complete answer with some images. 如果这没有意义,请告诉我,我会用一些图片给出一个完整的答案。 You may need to change you query to 您可能需要将查询更改为

SELECT * 
    FROM test_db 
    WHERE AccountNumber IN (@Account) 
        OR ISNULL(@Account, '' ) = ''

This will take care of blanks too. 这也将照顾空白。 So blanks/Null should return everything 所以blanks / Null应该归还一切

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

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