您想同时使用 LIKE 和多值参数,这是行不通的。但是,Reporting Services 使我们能够做几乎任何我们想做的事情。解决方案是使用自定义代码和表达式。首先,我们将您的 SQL 语句更改为表达式,如下所示:
="SELECT PASS_M, ENTRY_DT, EXIT_DT, WORKED_HRS, ACCESS_LOCATION_X, IC_N, "
&"COMPANY_M, CONSECUTIVE_D "
&"FROM TEMP_TARGET "
&"WHERE (CONSECUTIVE_D >= @consecDays) "
&"AND (ENTRY_DT BETWEEN @startDate AND @endDate) "
&"AND ((@accessvar IS NULL) OR (ACCESS_LOCATION_X LIKE @accessVar)) "
&"AND ((@icVar IS NULL) OR (IC_N LIKE @icVAr)) "
所以现在 SQL 语句实际上是一个字符串表达式,它将计算为一个将执行的 SQL 表达式。
接下来我们需要将您的多值参数转换为一系列LIKE
语句,我们可以使用自定义代码来完成。将以下自定义代码添加到您的报告中(右键单击报告,选择属性并单击代码选项卡):
Function AccessLocations (ByVal parameter As Parameter) AS String
Dim Result As String
If parameter.IsMultiValue then
Result = "AND ( "
For i as integer = 0 to parameter.Count-1
Result = Result + "(ACCESS_LOCATION LIKE '" + CStr(parameter.Value(i)) + "') OR "
Next
Result = Left(Result, Result.Length - 3) +") "
Else
Result = "AND (ACCESS_LOCATION LIKE '" + CStr(parameter.Value) + "') "
End If
Return Result
End Function
然后我们将此函数称为 SQL 语句的一部分:
Code.AccessLocations(Parameters!accessvar)
所以你的完整 SQL 是:
="SELECT PASS_M, ENTRY_DT, EXIT_DT, WORKED_HRS, ACCESS_LOCATION_X, IC_N, "
&"COMPANY_M, CONSECUTIVE_D "
&"FROM TEMP_TARGET "
&"WHERE (CONSECUTIVE_D >= @consecDays) "
&"AND (ENTRY_DT BETWEEN @startDate AND @endDate) "
& Code.AccessLocations(Parameters!accessvar)
&"AND ((@icVar IS NULL) OR (IC_N LIKE @icVAr)) "
如果您的参数中有%
通配符,那么这将起作用;否则将通配符添加到函数中。