Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamically sorting by ASC or DESC in SQL 7 SP
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Dynamically sorting by ASC or DESC in SQL 7 SP
Divers
Thread ID:
00429108
Message ID:
00429108
Vues:
45
All,

I'm having a problem with what should be a trivial undertaking.

I have a SP where I have 7 sort orders. 6 needs to be ASC (default) and 1 needs to be DESC. I cannot figure out how to implement this.

SELECT *
FROM (table)
WHERE (where)
ORDER BY
CASE @iorder
WHEN 0 THEN (sort1)
WHEN 1 THEN (sort2)
WHEN 2 THEN (sort3)
WHEN 3 THEN (sort4)
WHEN 4 THEN (sort5)
WHEN 5 THEN (sort6)
WHEN 6 THEN (sort7)
ELSE (default)
END
ASC

I thought I could do a

CASE @iorder
WHEN 3 THEN DESC
ELSE ASC
END
no go (according to the syntax checker). Any ideas to assign ASC or DESC based on the sort order?

TIA,
Doug
Douglas Osborne
Don't spend your life just wishing - http://www.AllGiftRegistry.com
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform