【发布时间】:2017-03-30 15:35:52
【问题描述】:
我正在 SSRS 中创建报告,并有一个参数供最终用户搜索帐号。在报告中,该参数默认设置为 null 以显示所有帐户。当参数不为空时,用户应该能够输入单个帐户或多个帐户,以逗号分隔。我的问题是当我尝试输入多个帐户时出现此错误:
“在预期条件的上下文中指定的非布尔类型的表达式,靠近 ','。”
这是我的 sql 查询:
SELECT * FROM test_db WHERE (AccountNumber IN (@Account)) OR (@Account IS NULL)
@Account 参数上的代码是
=IIF(IsNothing(Parameters!Account.Value),Parameters!Account.Value,Split(Parameters!Account.Value,","))
【问题讨论】:
-
@Account 是如何声明的?
-
SELECT * FROM test_db WHERE (AccountNumber IN (@Account)) OR (AccountNumber IS NULL) 你可能是这个意思。在 OR 中使用 AccountNumber 而不是 @Account
-
@Account 是 SSRS 中的数据类型 Text 和数据库中的 varchar(30)。我尝试根据您的建议调整 sql 查询,但是当参数为空时它不会显示所有帐户
-
您需要使用动态 SQL。类似 .. exec ('select * from test_db where (AccountNumber in (' + @Account + ')) OR AccountNumber IS NULL' )
-
是逗号分隔的吗?如果是这样,您需要将其拆分以执行 In 语句。
标签: sql reporting-services split ssrs-2012