Vertically align option for concatenated strings
When concatenating strings, it'd be nice to be able to align the "+" sign. The following is what I get now:
SELECT CASE
WHEN Col = 1
THEN 'Col 1'
ELSE ''
END + CASE
WHEN Col = 2
THEN 'Col 2'
ELSE ''
END + CASE
WHEN Col = 3
THEN 'Col 3'
ELSE ''
END + CASE
WHEN Col = 4
THEN 'Col 4'
ELSE ''
END AS ConcatStr
FROM #Test;
But what I'd like to get is:
SELECT CASE
WHEN Col = 1
THEN 'Col 1'
ELSE ''
END
+ CASE
WHEN Col = 2
THEN 'Col 2'
ELSE ''
END
+ CASE
WHEN Col = 3
THEN 'Col 3'
ELSE ''
END
+ CASE
WHEN Col = 4
THEN 'Col 4'
ELSE ''
END AS ConcatStr
FROM #Test;
-
Lee Robinson commented
This is part of a bigger issue. the "+" is an "infix" operator. All infix operators should be allowed to be aligned this way. This includes "AND", "OR" and arithmetic operators. The first operand, in this situation the first operand is the first "CASE" should be aligned with the next "CASE" and the "+" to the left. It would be similar to the way columns and commas are aligned. Commas can be considered "infix operators" also.
-
Vern Rabe commented
Okay, I've got the display formatting figured out... Here's what I get:
SELECT CASE
-----------WHEN Col = 1
---------------THEN 'Col 1'
-----------ELSE ''
-----------END + CASE
---------------------WHEN Col = 2
-------------------------THEN 'Col 2'
---------------------ELSE ''
---------------------END + CASE
-------------------------------WHEN Col = 3
-----------------------------------THEN 'Col 3'
-------------------------------ELSE ''
-------------------------------END + CASE
-----------------------------------------WHEN Col = 4
---------------------------------------------THEN 'Col 4'
-----------------------------------------ELSE ''
-----------------------------------------END AS ConcatStr
---FROM #Test;But what I'd like to get is:
SELECT CASE
-----------WHEN Col = 1
---------------THEN 'Col 1'
-----------ELSE ''
-----------END
------+ CASE
-----------WHEN Col = 2
---------------THEN 'Col 2'
-----------ELSE ''
-----------END
------+ CASE
-----------WHEN Col = 3
---------------THEN 'Col 3'
-----------ELSE ''
-----------END
------+ CASE
-----------WHEN Col = 4
---------------THEN 'Col 4'
-----------ELSE ''
-----------END AS ConcatStr
---FROM #Test; -
Vern Rabe commented
Well, the comment format is not at all what I submitted. I'll try again:
SELECT CASE
WHEN COL = 1
THEN 'COL 1'
ELSE ''
END + CASE
WHEN COL = 2
THEN 'COL 2'
ELSE ''
END + CASE
WHEN COL = 3
THEN 'COL 3'
ELSE ''
END AS ConcatStr
FROM #Test;What I'd like to get is:
SELECT CASE
WHEN COL = 1
THEN 'COL 1'
ELSE ''
END
+ CASE
WHEN COL = 2
THEN 'COL 2'
ELSE ''
END
+ CASE
WHEN COL = 3
THEN 'COL 3'
ELSE ''
END AS ConcatStr
FROM #Test