0

I have a report builder 3.0 report that has several parameters on it. Specifically, an account number (Defined as char(12) in the database). The database is a vendor supplied database, so I have zero control over the database schema.

My question is when I have a free form parameter for account id, how is that transformed into the query sent to the sql database?

The way I handle these free form fields is that I have a user defined function:

Public Function ConvertStringtoArray(sourceString as String) As string()
    Dim arrayOfStrings() As String
    Dim emptyString as String = " "
    If String.IsNullOrEmpty(sourceString) Then
    arrayOfStrings = emptyString.Split(",")
    Else
    arrayOfStrings = sourceString.Replace(" ", "").Split(",")
    End If
    return arrayOfStrings
End Function

And the parameter is defined as: @AcctList = code.ConvertStringToArray(Parameters!AcctList.Value)

The sql query has this in the where clause: Ac.Account_ID In (@AcctList)

My question is how does it build the In Clause. Will it literally be something like: Where Ac.Account_ID In (N'Acct1',N'Acct2').

I'm thinking it is, and the reason I think it's important is the query when I am running it in SSMS will run in less than 1 Second if my where clause has Where Ac.Account_ID In ('TGIF').. But it will take 13+ Seconds if I have Where Ac.Account_ID In (N'TGIF'). The total dataset returned is only 917 Rows.

The database I am querying is a 2008 R2 SP2, with the compatibility set to SQL 2008.

4

1 回答 1

1

您的假设对于“在(@parameter)中的东西”的谓词实际上是“在('value1','value2'等)中的东西”的谓词是正确的。前提是 @parameter 允许多个值。但是,您可以将参数绑定到查询以及使用代码。您可以拥有除主数据集之外的数据集,例如简单的“从值中选择值”,其中的值将是参数选择所需的值表。除非您必须进行字符串拆分,否则这通常效率更高。

于 2013-08-09T21:51:16.120 回答