Sql server Row to column pivot, known column names unknown row data values -


i've seen posts on row column pivots require knowing 1) possible values in row pivot, or 2) number of values pivot same each pivot group. here situation. have table describes real property:

parcel     legal                acreage 1001       portion nw1/4        0 1001       , sw1/2 38-9       0 1001       acc. plat #882    320.00 1002       portion 38-10        320.00 

the list of entries correspond single distinct value of parcel 1 5. last entry has actual acreage property, don't need 0's. want become this:

parcel     legal01              legal02           legal03              legal04         legal05          acres 1001       portion nw1/4        , sw1/2 38-9    acc. plat #882    <null>           <null>          320 1002       portion 38-10        <null>             <null>               <null>         <null>            320         

any insight appreciated.

use row_number

select *  (select parcel, legal,          sum(acreage) on (partition parcel) acres,          row_number() on (partition parcel order legal ) rn   yourtable) src pivot (max(legal) rn in ([1],[2],[3],[4],[5])) p 

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? -