1
0
Fork 0
mirror of https://github.com/treffynnon/sqlstyle.guide.git synced 2025-03-09 12:49:51 -05:00

Fix CASE formatting

This commit is contained in:
apurvis@lumoslabs.com 2016-12-27 14:41:52 -05:00
parent 7b2a5fba55
commit 23242db50c

View file

@ -331,30 +331,32 @@ FROM table
Or WHEN/END should have 2 space left justification, and `WHEN`/`THEN` should be indented the same as the `ELSE`/`value`. Or WHEN/END should have 2 space left justification, and `WHEN`/`THEN` should be indented the same as the `ELSE`/`value`.
```sql ```sql
SELECT CASE SELECT
WHEN x > y AND x < z CASE
THEN 'x more than y but less than z' WHEN x > y AND x < z
WHEN x > y AND x > z THEN 'x more than y but less than z'
THEN 'x more than y and more than z' WHEN x > y AND x > z
ELSE THEN 'x more than y and more than z'
'x and y not related' ELSE
END AS city, 'x and y not related'
street_address, END AS city,
phone_number street_address,
phone_number
FROM office_locations FROM office_locations
``` ```
#### Case statements (MySql) #### Case statements (MySql)
```sql ```sql
SELECT CASE postcode SELECT
WHEN 'BN1' CASE postcode
THEN 'Brighton' WHEN 'BN1'
WHEN 'EH1' THEN 'Brighton'
THEN 'Edinburgh' WHEN 'EH1'
END AS city, THEN 'Edinburgh'
street_address, END AS city,
phone_number street_address,
phone_number
FROM office_locations FROM office_locations
``` ```
@ -370,12 +372,13 @@ FROM office_locations
likely should be. likely should be.
```sql ```sql
SELECT CASE postcode SELECT
WHEN 'BN1' CASE postcode
THEN 'Brighton' WHEN 'BN1'
WHEN 'EH1' THEN 'Brighton'
THEN 'Edinburgh' WHEN 'EH1'
END AS city THEN 'Edinburgh'
END AS city
FROM office_locations FROM office_locations
WHERE country = 'United Kingdom' WHERE country = 'United Kingdom'
AND opening_time BETWEEN 8 AND 9 AND opening_time BETWEEN 8 AND 9