SQL Server Row to Cols -


i seems simple task need sql experts one.

table samples , requested result

the number of contacts can vary 1 30 persons , want phone numbers in 1 row per cust_ref.

how can this??

this solution without dynamic sql, please try out:

declare @contacts table(cust_ref int,phone varchar(100)); insert @contacts values(10000,'ph10000a'),(10000,'ph10000b'),(10000,'ph10000c')                            ,(10001,'ph10001a'),(10001,'ph10001b'),(10001,'ph10001c')                             ,(10002,'ph10002a'),(10002,'ph10002b');  select p.* (      select 'phone'+replace(str(row_number() over(partition cust_ref order phone),2),' ','0') inx,*     @contacts     ) tbl pivot (     min(phone) inx in(phone01,phone02,phone03,phone04) --type more... ) p         

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -