all groups > sql server reporting services > august 2004 >
You're in the

sql server reporting services

group:

Passing Parms To SQL


Passing Parms To SQL geomanks NO[at]SPAM yahoo.com
8/15/2004 9:02:04 AM
sql server reporting services:
I tried for hours to pass a parm to a query like this:

Select * from Table1 order by @SortField

I defined sortfield as a parm in the report parm tab as well as in the
sql statement parm tab. I used the generic designer to test it and
when it prompted me for the parm I put in the correct column name to
sort on. I kept getting a SQL error about passing a wrong parm to an
order by clause. It never worked. I didn't know how to see the
generated SQL to see what was wrong.
I got the same error when I ran the report and passed the same column
name.

I got around this by turning the SQL into a expression and passing the
parm with the parm clause like this

="Select * from Table1 order by " & Parameters!SortField.Value

I am glad it is working but why didn't the first way work?

Thanks!

Re: Passing Parms To SQL Lev Semenets [MSFT]
8/16/2004 12:56:21 PM
I'm sure parameters cannot be used directly in ORDER BY.
If you do not want to use dynamic query you may consider using CASE ... WHEN
....

select * from Table1
order by
case @SortField
when 'Field1' then Field1
when 'Field2' then Field2
...
end
--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]

Re: Passing Parms To SQL geomanks NO[at]SPAM yahoo.com
8/16/2004 4:16:53 PM
Hey Microsoft guys? Any reason no one is responding to this? Did I ask it wrong?
Sheila

[quoted text, click to view]
Re: Passing Parms To SQL Bruce Loehle-Conger
8/17/2004 10:06:15 AM
Did you see the reply from around 3. You wrote this at around 6 so it seems
like you didn't see the answer from MS.

Bruce L-C

[quoted text, click to view]

AddThis Social Bookmark Button