Srinivas Srinivas - 1 year ago 73
SQL Question

Select SQL Columns as added rows

I have a SQL Server 2008 table as below...

ID Others1Desc Others1Value Others2Desc Others2value
-- ----------- ------------ ----------- ------------
id_x xyz 12.50 pqr 10.00
id_y abc NULL mno 1.05

Now, I want the select result as below...

ID ItemDesc ItemValue
-- ----------- ------------
id_x xyz 12.50
id_x pqr 10.00
id_y abc NULL
id_y mno 1.05

Any guidance is highly appreciated. Thanks

Answer Source

This way:

select ID, Others1Desc as ItemDesc,Others1Value as itemValue from
(select ID ,   Others1Desc ,   Others1Value from table1

Union all

select ID ,   Others2Desc,   Others2value from table1)as a
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download