Wednesday, March 7, 2012

Question about a SQL Reporting Tutorial Example

In the BOL "Walkthrough - Using a Dynamic Query in a Report" it says:
In Data view, select the Employees dataset, and then use the generic
query designer to replace the original query with the following
expression:
="SELECT FirstName, LastName, Title FROM Employee" &
IIf(Parameters!Department.Value = 0,""," WHERE (DepartmentID = " &
Parameters!Department.Value & ")") & " ORDER BY LastName"
This expression
If I put that in the generic query designer it will not validate the
SQL.
Can anyone help with this?Expression-based queries cannot be validated and executed in the generic
query designer, because it does not evaluate the VB.NET expressions. They
are only evaluated at report runtime.
The general recommendation for dynamic queries using VB.NET expressions is
to start with a static query, then add a textbox to the report with the
dynamic query expression you want to use. Run the report to verify that the
expression-based commandtext evaluates to valid SQL, and then in the last
step replace the static query with the dynamic expression-based query. In
addition, the fields list is only auto-detected from non expression-based
queries.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Chris" <cmay@.walshgroup.com> wrote in message
news:44f6e099.0409051123.191910b6@.posting.google.com...
> In the BOL "Walkthrough - Using a Dynamic Query in a Report" it says:
> In Data view, select the Employees dataset, and then use the generic
> query designer to replace the original query with the following
> expression:
> ="SELECT FirstName, LastName, Title FROM Employee" &
> IIf(Parameters!Department.Value = 0,""," WHERE (DepartmentID = " &
> Parameters!Department.Value & ")") & " ORDER BY LastName"
> This expression
> If I put that in the generic query designer it will not validate the
> SQL.
> Can anyone help with this?

No comments:

Post a Comment