[dba-SQLServer] Control of SortOrder?

pcs at azizaz.com pcs at azizaz.com
Wed Oct 10 22:41:21 CDT 2007


Hello,

SQL2005

Based on the value of an input parameter I want to control 
the SortOrder on a particular column.

Can it be done, and if so how?

I've been trying with CASE statements .. no luck, I'm stuck!

I've tried

ORDER BY
T2.HighestQualificationEnum (CASE WHEN @p7_ReqPosID = 0 THEN 
ASC ELSE DESC END),
T3.Ranking,
@p2_intNumberOfDays-
	CASE
	 WHEN datediff(d, CONVERT(DATETIME, 
@p1_ReqStartDate , 102),T1.StartDate)>=@p2_intNumberOfDays
	 THEN @p2_intNumberOfDays
	 ELSE datediff(d, CONVERT(DATETIME, 
@p1_ReqStartDate , 102),T1.StartDate)
	END

(The last sortorder item that also includes a CASE statement 
works!)

regards
borge



More information about the dba-SQLServer mailing list