這將做你想做的假設數據類型相互兼容
order by
case @pcsort
when '' then compcode
else received
end ASC,
compcode ASC
更一般地,你需要爲每個排序列一個CASE假設數據類型是兼容
order by
case @pcsort
when '' then compcode
else received
end ASC,
case @pcsort
--safe to sort on same column agaon , or use a constant
when '' then compcode or <constant of same type as compcode>
else compcode
end ASC
如果數據類型是不兼容的,你需要更多的案例和大量的常量
order by
case @pcsort
when '' then compcode
else <constant of same type as compcode>
end ASC,
case @pcsort
when '' then <constant of same type as received>
else received
end ASC,
case @pcsort
when '' then <constant of same type as compcode>
else compcode
end ASC
來源
2011-05-06 09:08:35
gbn
「compcode」和「received」的數據類型是什麼? – 2011-05-06 09:08:12