Information générale
Forum:
Microsoft SQL Server
Catégorie:
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.
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement