Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ordering
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Divers
Thread ID:
00544830
Message ID:
00544854
Vues:
10
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
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform