I have following table:
Cus_ID Work_Phone Home_Phone Mobile_Phone
1 x Blank x
2 x x Blank
3 x x x
.
.
. and so on (1000s of rows)
Work_Phone, Home_Phone, Mobile_Phone - varchar
x = some value present
I need to select from Source data to move it Target system like below, I need to create separate row for unique values for each Cus_ID. How do i do it?
Cus_ID Type ContactNo
1 Work x
1 Mobile x
2 Work x
2 Home x
3 Work x
3 Home x
3 Mobile x
.. and so on
Type, ContactNo - varchar
x = Should be the corresponding value from Source table
Assuming
col1
,col2
andcol3
are of the same type, then:Edit edit: here's the version with
ISNULL
tests, column headings and the rest, in response to your revised question:If there's a chance the "blank" column may contain whitespace characters, then refine it yet further to:
etc.