Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Form rows to columns

Author  Topic 

gnaus
Starting Member

41 Posts

Posted - 2011-11-30 : 05:15:27
Dear reader,

I have this table. I want to make colums from the rows.
Al “Opmerkingen” with the same “ClientnrQzorg” on ONE row, so multiple colums “Opmerkingen” (in stead of now, multiple rows per “ClientnrQzorg”).



ClientnrQzorg Opmerkingen Besluitnummer
CL010001 5-3-08 aanvraag binnen bij t informatie.. 5
CL010001 23-4-08 indicatie binnen op t AZR, VP.. 106
CL010001 25-2-09 indicatie binnen op t.. 107
CL010001 9-11-09 indicatie binnen op.. 108
CL010002 26-9-07 aanvraag binnen op t AZR.. 1
CL010002 19-12-07 indicatie binnen op t AZR.. 102
CL010002 16-11-09 indicatie binne op AZR.. 103
CL010003 18-3-09 LET OP: Dit blijkt… 1



So I want the result to be:


ClientnrQzorg Opmerkingen1 Opmerkingen2 Opmerkingen3 Opm4
CL010001 5-3-8 aanvr. 23-4-08 indicat.. 25-2-09 indicatie.
CL010002 26-09-07 a… 19-12-07 indic.. .. etc
CL010003 18-3-09 LET..


But also I want that it’s clear wich “Opmerkingen” belongs to wich “Besluitnummer”!!!


Thank you!
(ps I found something about Pivot’s etc. on this forum, but I couldn’t translate quite well to my situation)

I tried This:

select 'Opmerkingen'
[1],[2],[3],[4],[5],[6],[7],,[9],[10],[11]
from EigOpmIndicatieEnClientnrQzorgAlleKaarten



PIVOT

(

group by(ClientnrQzorg)

FOR

[Opmerkingen]

IN ( [1], [2],[3],[4], [5],[6],[7], ,[9],[10], [11],[12])

)

order by ClientnrQzorg



error Msg 156, Level 15, State 1, Line 11
Incorrect syntax near the keyword 'group'.



GN

GN

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-30 : 06:11:35
duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=168546


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -