Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, i need the below source data to be pivoted(rows to columns).
Could you please help me with the SQL to achieve this.
The simplest solution would be the regular case based pivot, e.g.
select dt, lst_yr_dt, lst2_yer_dt, region, bird,
max(case when desg = 'svp' then orid end) as svp_orid,
max(case when desg = 'vp' then orid end) as vp_orid,
etc.
from SourceData
group by dt, lst_yr_dt, lst2_yer_dt, region, bird