I have a row with data a , b , c , d. I would like to create a unique row for each one. The end result would be row 1 a = has data , b = no data , c = no data , d = no data row 2 a = no data b = has data c = no data d = no data . And so on and so forth. This would turn each row into 5 flatten rows of data. If you have any advice or a way to break these rows into flatter data that would be awesome. I would also like to add a date to each of these flatten rows a = 1/1/2014 b = 2/1/2014 etc. Thank you
Asked
Active
Viewed 372 times
1 Answers
2
You need to use UNION. By using union you can join multiple select statements into one result set.
SELECT a, null as b, null as c, null as d, '1/1/2014' FROM TABLE
UNION
SELECT null as a, b, null as c, null as d, '2/1/2014' FROM TABLE
UNION
SELECT null as a, null as b, c, null as d, '3/1/2014' FROM TABLE
UNION
SELECT null as a, null as b, null as c, d, '4/1/2014' FROM TABLE

Jeffrey Wieder
- 2,336
- 1
- 14
- 12
-
I have about 85 rows I need to break up, is there anyway to automate it more or will I need to do that for each row? – David Sep 08 '14 at 18:05
-
Yes, [here](http://stackoverflow.com/questions/13372276/simple-way-to-transpose-columns-and-rows-in-sql) is another post with a similar request that should help. – Jeffrey Wieder Sep 08 '14 at 18:13