all groups > sql server reporting services > october 2006 >
You're in the

sql server reporting services

group:

Using variables in text dataset does not work


Using variables in text dataset does not work Jason Rodman
10/31/2006 9:42:02 AM
sql server reporting services: I have a query that I am using in my report as a text dataset (i dont want it
in a stored proc yet) but my issues is that I have a variable defined that I
want to become a parameter for the report. What happens is if I refer to the
variable at all before the select statement its used in, it does not appear
in the parameters list and is not prompted for. For example, this works fine:

Select * from anytable where field = @variable

But, if you use a set statement before it, it disappears from your
parameters list:

set @variable = ltrim(@variable)
Select * from anytable where field = @variable

RE: Using variables in text dataset does not work Jason Rodman
10/31/2006 9:56:03 AM
I also found out something new about this. If I change my SET statements to
SELECT statements, it fixes the problem, but a new one pops up. Now, RS
thinks that the variable I am using is the wrong data type. How does RS know
what datatype to make the variable?

[quoted text, click to view]
Re: Using variables in text dataset does not work Bruce L-C [MVP]
10/31/2006 12:44:03 PM
Go to layout tab, click anywhere so the Report menu shows up. Report
Parameters. Set to the appropriate datatype.

As far as it disapppearing. My guess is because you use set it assumed this
was a local variable, not a parameter (and rightly so).

Note that you can map query parameters to an expression instead of directly
to the parameter. The fact that you used the select maybe caused it to stay
in the parameter list but because you are doing a trim it assumes it is a
text parameter (again guessing).

I suggest you stop trying to actually create your stored procedure logic
this way. Instead, first create and test your stored procedure outside of
the report Or just put in the very minimal amount needed (i.e. no ltrim)
just enough to allow you to get back the right data.

Also, in your stored procedure do the following:
1. leave out set nocount on
2. Let SQL server do the object lifetime management. If you use temp tables
don't explicitly drop them. Let SQL Server handle temp table cleanup. Have
the last statement be a select on your temp table and then exit the stored
proc.


--
Bruce Loehle-Conger
MVP SQL Server Reporting Services

[quoted text, click to view]

AddThis Social Bookmark Button