sql server - SQL query to transpose data in below case -


i have following sql server 2008 table:

heading     limit   package x charges   200     x charges   300     b x charges   400     c x charges   500     d y charges   550     y charges   450     b y charges   350     c y charges   250     d 

now data in following representation:

heading    package_a   package_b  package_c  package_d x charges  200         300        400        500 y charges  550         450        350        250 

please try:

select   heading,    package_a,   b package_b,   c package_c,   d package_d (       select * yourtable )  pivot (sum(limit) package in (a, b, c, d)) pvt 

sql fiddle


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -