Question : sql (2005) query - code to combine multiple columns into one

Greetings all -

I'm working with a table that has a unique ID with additional 5 columns (ie: ID, A, B, C, D, E) and I'd like to pivot it into a table so that the ID is no longer unique and the 5 individual columns are combined into one (ie: ID, EntryVal).

The only way I can think of doing this is to write 5 different queries, each pulling in one of the columns and then combining it into the new table structure, is there an easire/more efficient way of doing this without using multiple queries?

Answer : sql (2005) query - code to combine multiple columns into one

If you have columns from A-F, include all those.

select ID,A as EntryVal from YourTable union all
select ID,B as EntryVal from YourTable union all
select ID,C as EntryVal from YourTable union all
select ID,D as EntryVal from YourTable union all
select ID,E as EntryVal from YourTable union all
select ID,F as EntryVal from YourTable
Random Solutions  
 
programming4us programming4us