xhostx
Constraint Violating Yak Guru
277 Posts |
Posted - 2014-02-11 : 10:27:00
|
[code]CREATE TABLE pvt (VendorID int, Emp1 int, Emp2 int, Emp3 int, Emp4 int, Emp5 int);GOINSERT INTO pvt VALUES (1,4,3,5,4,4);INSERT INTO pvt VALUES (2,4,1,5,5,5);INSERT INTO pvt VALUES (3,4,3,5,4,4);INSERT INTO pvt VALUES (4,4,2,5,5,4);INSERT INTO pvt VALUES (5,5,1,5,5,5);GO--Unpivot the table.SELECT VendorID, Employee, OrdersFROM (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5 FROM pvt) pUNPIVOT (Orders FOR Employee IN (Emp1, Emp2, Emp3, Emp4, Emp5))AS unpvt;GO[/code]here's the link : http://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx--------------------------Joins are what RDBMS's do for a living |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2014-02-12 : 04:30:35
|
[code]declare @table table(Date1 date, Date2 date, Date3 date)insert into @table select '2013-02-01','2013-03-01','2013-04-01'select urs_column from @tablecross apply(select Date1 union all select Date2 union all select Date3)upvt(urs_column)[/code] |
|
|