How can I use
ORDER BY
CASE @AccountOperator
WHEN '>' THEN AccountTrxValue
END ASC,
CASE @AccountOperator
WHEN '<' THEN AccountTrxValue
END DESC
when AccountTrxValue is an alias and a result of the following in the "select"?
CASE WHEN PAA.RedeemValue>0 THEN
PAA.RedeemValue * -1
ELSE PAA.EarnValue END
AS AccountTrxValue ,
It dosesn't accept the alias because of the case
(without using sub query)
EDIT:
so someone answered me and I did it that way:
ORDER BY
CASE
WHEN @AccountOperator IS NULL OR @AccountOperator IN ('>','=') THEN
CASE WHEN PAA.RedeemValue>0 THEN
PAA.RedeemValue * -1
ELSE PAA.EarnValue END
END DESC,
CASE
WHEN @AccountOperator = '<'THEN
CASE WHEN PAA.RedeemValue>0 THEN
PAA.RedeemValue * -1
ELSE PAA.EarnValue END
END
How can I write it in a shorter way? *I couldn't include the null in the "in" * I had to do 2 cases because it seems that "desc" should be written after the "end"