sql server - T-SQL for "Not quite a Pivot" -
i have following source data (the data extract source of several hundred rows.):
id codeid code 3749 69 354 3750 69 864 33721 130 xxx 33722 130 319 30446 159 xxx 30447 159 xxx and using t-sql need achieve:
codeid code1 code2 69 354 864 130 xxx 319 159 xxx xxx this doesn't seem fit structure pivot table , have no idea how achieve this. have suggestions.
you can pivot if first assign each of values number using row_number()
select codeid, [1] code1,[2] code2 -- .... ,[3] etc ( select codeid, code, row_number() on (partition codeid order id) rn yourtable ) p pivot (max(code) rn in ([1],[2])) p2 --, [3]... etc
Comments
Post a Comment