A cursor is never the best way:-- setupDECLARE @t TABLE(LAST VARCHAR(30), FIRST VARCHAR(30), [CASE] VARCHAR(30), Amount VARCHAR(30))INSERT @t VALUES('Smith', 'Greg', '01', '100')INSERT @t VALUES('Doe', 'Joe', '02', '200')-- querySELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) #, val FROM @t aUNPIVOT(val FOR col IN ([LAST],[FIRST],[CASE],[Amount])) b
Note that you cannot guarantee order without an ORDER BY clause, so it's possible that the values could be sorted incorrectly.