I have the following SELECT …
SELECT CASE WHEN cola < 0 THEN '-'
WHEN cola > 0 THEN '+'
ELSE '='
END
SUM(colb), SUM(colc), SUM(cold),
MAX(CASE WHEN cola < 0 THEN 1
WHEN cola > 0 THEN 3
ELSE 2
) AS Sort
FROM Table1
WHERE this = that
GROUP BY CASE WHEN cola < 0 THEN '-'
WHEN cola > 0 THEN '+'
ELSE '=' END
ORDER BY cold
This is what I’m getting:
cola colb colc cold
- 1 2 1
+ 13 0 3
This is what I’m wanting:
cola colb colc cold
- 1 2 1
= 0 0 2
+ 13 0 3
When I get a result set I have ‘+’ and ‘-‘ rows but no ‘=’ row because there weren’t any ‘0’ values to trigger the ELSE. How can I have it set so that if this is the case then it would still have a ‘=’ row in my SELECT statement?
Thanks! *If more of the select is required just let me know.
You may need a derived table for Table1 too to apply the filter correctly. You can push th CASE into this
Edit, after comments, even simpler thanks to @WReach