Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ordering
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Miscellaneous
Thread ID:
00544830
Message ID:
00544985
Views:
11
>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
Map
View

Click here to load this message in the networking platform