Skip to content
Advertisement

how do I split one row to two rows based on column value

my input is :

PID   PDate     col2   source1     source2
1     20200324  24      AAA        BBB

And i am expecting below output:

PID   PDate     col2   source     
1     20200324  24      AAA        
1     20200324  24      BBB 

I tried using cross apply but not getting right output. Can anyone please help me?

Advertisement

Answer

UNION is the right way to solve this:

SELECT PID, PDate, col2, source1 as source FROM yourtable
UNION ALL
SELECT PID, PDate, col2, source2 FROM yourtable
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement