简体   繁体   English

Report Builder 3.0基础SQL

[英]Report Builder 3.0 underlying SQL

I have a report builder 3.0 report that has several parameters on it. 我有一个报表构建器3.0报表,上面有几个参数。 Specifically, an account number (Defined as char(12) in the database). 具体来说,是一个帐号(在数据库中定义为char(12))。 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? 我的问题是,当我具有帐户ID的自由格式参数时,该参数如何转换为发送到sql数据库的查询?

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) 该参数定义为:@AcctList = code.ConvertStringToArray(Parameters!AcctList.Value)

The sql query has this in the where clause: Ac.Account_ID In (@AcctList) sql查询在where子句中具有以下内容: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'). 从字面上看是否会是这样的:其中Ac.Account_ID在(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'). 我以为是这样,我认为很重要的原因是,如果我的where子句具有Where Ac.Account_ID In('TGIF'),则在SSMS中运行该查询时,查询将在不到1秒的时间内运行。如果我在哪里输入Ac.Account_ID(N'TGIF'),将花费13+秒。 The total dataset returned is only 917 Rows. 返回的数据集总数仅为917行。

The database I am querying is a 2008 R2 SP2, with the compatibility set to SQL 2008. 我要查询的数据库是2008 R2 SP2,其兼容性设置为SQL 2008。

You assumption is correct for the predicate of 'where thing in (@parameter)' actually being 'where thing in ('value1', 'value2', etc). 您的假设对于“(@parameter)中的where事物”实际上是“(value1”,“ value2”等)中的谓词是正确的。 Provided that @parameter allows multiple values. 前提是@parameter允许多个值。 However you can tie a parameter to a query as well as using code. 但是,您可以将参数绑定到查询以及使用代码。 You can have a dataset other than your main dataset like a simple 'Select value from values' where the values would be a table of values needed for a parameter choice. 您可以拥有除主要数据集以外的其他数据集,例如简单的“从值中选择值”,其中值将是参数选择所需的值表。 This is often much more efficient unless you have to do a string split. 除非必须进行字符串拆分,否则这通常会更有效率。

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

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