Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I use a variable ORDER BY clause?
Message
De
24/04/2007 09:01:34
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Can I use a variable ORDER BY clause?
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01219282
Message ID:
01219282
Vues:
52
Can I use a variable ORDER BY clause? It is rejected by the syntax parser as it wants the name of a column. Is there a way other than creating a different query for each?
Maybe using an ugly CASE WHEN in ORDER BY?

This is a very simplied stored proc to illustrate:
CREATE PROCEDURE dbo.sp_getWhatever
(
   @SortOrder char(10)
)
AS

SET NOCOUNT ON

SELECT o.Org_Name, c.CtryNm  -- extra sortable columns here
FROM Orgs AS o
INNER JOIN Countries AS c ON o.ctry_code = c.Ctry_Cd
ORDER BY @SortOrder
Still learning T-SQL :)


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform