Feature Description
Case Statements with multiple cases and conditions can currently get very messy, as each condition is aligned with the WHEN statement, but each WHEN is on the same line as the previous THEN. The intention with this request is that others in the community can also include their preferred formats.
In general, I format CASE statements as follows:
- Each WHEN on a new line (including the first one)
- Each condition on a new line (unless it's the only one
- THEN on a new line, indented one level
- END on a new line, level with CASE
The following illustrates these points:
Select
Case
When
a = 1
And c <> 0
Then 'a'
When
b = 1
And c <> 0
Then 'b'
When c = 1
Then 'c'
End As colname
From tbl;
Problem and Motivation
This is a spin-off from #22764
Having this feature would reduce the compliance friction with our team's established formatting standards, allowing queries to be quickly scanned and understood by all team members.
The sample query from the description currently gets formatted as follows, which can quickly get out of hand with the extreme indentation:
Select Case When a = 1
And c <> 0 Then 'a' When b = 1
And c <> 0 Then 'b' When c = 1 Then 'c' End As colname
From tbl;
Related Area
If you selected "Other", please describe the area
No response
Confirmation
Feature Description
Case Statements with multiple cases and conditions can currently get very messy, as each condition is aligned with the WHEN statement, but each WHEN is on the same line as the previous THEN. The intention with this request is that others in the community can also include their preferred formats.
In general, I format CASE statements as follows:
The following illustrates these points:
Problem and Motivation
This is a spin-off from #22764
Having this feature would reduce the compliance friction with our team's established formatting standards, allowing queries to be quickly scanned and understood by all team members.
The sample query from the description currently gets formatted as follows, which can quickly get out of hand with the extreme indentation:
Related Area
If you selected "Other", please describe the area
No response
Confirmation