Reputation: 155
I have a table in below format
and I want output like this
that means i want to show
Column 1,Column 2,Column 3,Column 4,Column 5,Column 6,Column 7
in First row and
Column 1,Column 2,Column 3,Column 4,Column 8,Column 9,Column 10
in Second row
and main problem is i am having 256 columns and i dont want to run same query again and again. So is there any way to solve this using loop or anything.?
Thank you in advance
Upvotes: 1
Views: 390
Reputation: 633
You can get this by using a union query. Add the OrderKey column to maintain the ordering of your rows.
SELECT Column1,Column2,Column3,Column4,Column5,Column6,Column7, 1 AS OrderKey
FROM [TableName]
UNION ALL
SELECT Column1,Column2,Column3,Column4,Column8,Column9,Column10, 2 AS OrderKey
FROM [TableName]
ORDER BY OrderKey
Upvotes: 2