I think I'm getting closer, but not sure:
I have an example table containing the email address of Personal and Work. I am trying to create a new table that contains one address.
Then insert the email address, for example: If the user has a work email, but does not have a personal email, an email to insert, and if there is no work email, insert a personal email.
The following code does not work, but it just shows some of the many options that I used:
USE EXAMPLE_DB
GO
CREATE TABLE USER_EMAIL(
USER_NBR CHAR(1) NOT NULL
,EMAIL VARCHAR(30)NULL
)
GO
INSERT INTO USER_EMAIL(
USER_NBR
,EMAIL
)
SELECT USER_NBR
,CASE WHEN EMAIL_ADDR IS NULL AND EMAIL_TYPE = 'Personal' THEN EMAIL_TYPE = 'Work' END EMAIL
,CASE WHEN EMAIL_ADDR IS NULL AND EMAIL_TYPE = 'Work' THEN EMAIL_TYPE = 'Personal' END EMAIL
FROM EMAIL_DATA
Here is the table for EMAIL_DATA:
USER_NBR EMAIL_TYPE EMAIL_ADDR
1 Personal
2 Personal user2personal@demo.com
3 Personal user3personal@demo.com
4 Personal
5 Personal user5personal@demo.com
1 Work user1work@demo.com
2 Work user2work@demo.com
3 Work
4 Work user4work@demo.com
5 Work
Thanks everyone!
source
share