I have a result set like this:
ID Value 1 100 2 50 3 200 4 30 - - - -
I want it to transform into following:
Value1 Value2 100 50 200 30 - - - -
How to do it with T-SQL?
I have a result set like this:
ID Value 1 100 2 50 3 200 4 30 - - - -
I want it to transform into following:
Value1 Value2 100 50 200 30 - - - -
How to do it with T-SQL?
Use this:
select a.Value, b.Value from ( select row_number() over(order by ID) [rn], Value from @t )a left join ( select row_number() over(order by ID) [rn], Value from @t )b on b.rn = a.rn + 1 where a.rn % 2 = 1 Sample data:
declare @t table (ID int, Value int) insert @t values (1,100), (2,50), (3,200), (4,30) Output:
Value Value ----------- ----------- 100 50 200 30