General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
>As you probably found out, SQL Server does not allow a parameterized ORDER BY clause. OTOH, you can use the CASE function within the ORDER BY:
>
>SELECT ...
>FROM thetable
>ORDER BY CASE @resort
> WHEN 'City' THEN citycolumn
> WHEN 'State' THEN statecolumn
> ...
> OTHERWISE somethinghereifyouwant
> END
>
>The only thing to consider is that SQL Server will consider the data type of the CASE function based on the last item in the list. Make sure that you convert everything to the same data type.
>
>-Mike
Thank you Michael, I will give that a try.
John.
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only