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:
CREATEPROCEDURE dbo.sp_getWhatever
(
@SortOrder char(10)
)
ASSETNOCOUNTONSELECT o.Org_Name, c.CtryNm -- extra sortable columns hereFROM Orgs AS o
INNERJOIN Countries AS c ON o.ctry_code = c.Ctry_Cd
ORDERBY @SortOrder
"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