Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Pivot - dynamic columns

$
0
0
hi to all,I just wonder how to to solve this...The first select is running fine but due to extra values added to the table the list of manual difined columns must be added manualy each time new values occur.Is it possible to make the PIVOT's IN clause dynamicly as stated in the second script (it is based on the same table #source)when running it prompts the next error;Msg 156, Level 15, State 1, Line 315Incorrect syntax near the keyword 'select'.Msg 102, Level 15, State 1, Line 315Incorrect syntax near ')'. adding or moving ')' or '(' are not working.......anyone ??Regards,Guus Kramer----------------------------------------------------------------------------------------select * into #tempfrom #sourcepivot ( avg(value) for drive in ([C], [D], [E], [F], [G], [H], [T], [U], [V] )) as valueselect * from #temp order by .........versusselect * into #tempfrom #sourcepivot ( avg(value) for drive in (select distinct(column) from #source)) as valueselect * from #temp order by .....----------------------------------------------------------------------------------------

Viewing all articles
Browse latest Browse all 3145

Trending Articles