Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Services / Reporting Services / October 2006

Tip: Looking for answers? Try searching our database.

Using variables in text dataset does not work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Rodman - 31 Oct 2006 18:42 GMT
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

Any ideas why this is happening?
Jason Rodman - 31 Oct 2006 18:56 GMT
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?

> 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
[quoted text clipped - 11 lines]
>
> Any ideas why this is happening?
Bruce L-C  [MVP] - 31 Oct 2006 19:44 GMT
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.

Signature

Bruce Loehle-Conger
MVP SQL Server Reporting Services

>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
[quoted text clipped - 22 lines]
>>
>> Any ideas why this is happening?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.