I have the following SQL code:
SELECT eml AS "Email Address"
FROM emailtbl
WHERE DEPT LIKE 'E%'
My issue is that if the department starts in 'F' I must select fax instead of eml. What could I do to select eml if the dept starts with 'E' and select fax if the dept starts in 'F'
Thanks
One option is to use a UNION ALL
statement
SELECT eml AS "Entity"
FROM emailtbl
WHERE DEPT LIKE 'E%'
UNION ALL
SELECT fax AS "Entity"
FROM emailtbl
WHERE DEPT LIKE 'F%'
another one is to use a CASE
statement
SELECT CASE WHEN Dept LIKE 'E%' THEN eml ELSE fax END AS "Entity"
FROM emailtbl
WHERE DEPT LIKE 'E%' OR DEPT LIKE 'F%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With