Skip to main content

CASE THEN Alignment

When alignCaseThen is enabled, THEN keywords are vertically aligned across WHEN branches by padding with spaces after the condition.

Basic aligned THEN

select case when status = 'active' then 'A' when x then 'X' end from t
select case when status = 'active' then 'A' when x then 'X' end from t

Varying condition widths

select case when a then 1 when abc then 2 when abcdef then 3 end from t
select case when a then 1 when abc then 2 when abcdef then 3 end from t

Disabled by default

select case when status = 'active' then 'A' when x then 'X' end from t
select case when status = 'active' then 'A' when x then 'X' end from t

Single WHEN — no alignment needed

select case when x then 'A' end from t
select case when x then 'A' end from t

With ELSE

select case when status = 'active' then 'A' when x then 'X' else 'Z' end from t
select case when status = 'active' then 'A' when x then 'X' else 'Z' end from t

Long CASE with alignCaseThen

select case when status = 'A' then 'Active' when status = 'I' then 'Inactive' when status = 'P' then 'Pending' when status = 'R' then 'Rejected' when status = 'D' then 'Deleted' when status = 'S' then 'Suspended' when status = 'X' then 'Expired' when status = 'C' then 'Completed' else 'Unknown' end from t
select
case
when status = 'A' then 'Active'
when status = 'I' then 'Inactive'
when status = 'P' then 'Pending'
when status = 'R' then 'Rejected'
when status = 'D' then 'Deleted'
when status = 'S' then 'Suspended'
when status = 'X' then 'Expired'
when status = 'C' then 'Completed'
else 'Unknown'
end
from t