Reputation: 1625
I am selecting some data where we have a set of peoples names, and also a list of preferred names, which may or may not be null. I am checking to see if the preferred first name is null, if it is use the a different table for the name. I understand I need to use a case statement for this, any insight or tips would be appreciated.
Example:
SELECT sp1.PREF_FIRST_NAME
CASE
WHEN sp1.PREF_FIRST_NAME is null
THEN s1.FIRST_NAME as "Pref_Name"
ELSE sp1.PREF_FIRST_NAME as "Pref_Name"
END
FROM TABLE1 sp1,TABLE2 s1
Upvotes: 0
Views: 3232
Reputation: 204794
SELECT sp1.PREF_FIRST_NAME, CASE WHEN sp1.PREF_FIRST_NAME is null
THEN s1.FIRST_NAME
ELSE sp1.PREF_FIRST_NAME
END as "Pref_Name"
FROM TABLE1 sp1,TABLE2 s1
Upvotes: 1