Separate (one-line) format for simple "when then else end" statement
It would be nice to be able to specify a separate format for simple case statements with only one 'when' and possibly an 'else' clause. These can typically easily fit in one line, while complicated case statements benefit from taking up the additional lines to improve readability.
declare @profit float = 10
/* Simple case statement can fit on one line */
select case when @Profit > 0 then 'Great' else 'Not so great' end
/* Complex case statement requires multiples lines */
select case
when @Profit > 10000 then 'Nice!'
when @Profit > 0 then 'OK'
else 'You''re fired!'
end
-
Damien Schoof commented
I would like to extend this to cover a few more cases as well.
E.g. if I have an if statement:
IF NOT EXISTS (SELECT * FROM myTable WHERE MyID = 3)
BEGIN
/* Do stufff */
ENDI would like the SELECT statement here to stay on one line unless it is too long.