Question : SQL 2005 Data configuration help

Hi,

I am having a problem manipulating some data, and not sure if there is an easy way of doing this.

My data currently is displayed like so:

HSE_READER_ID      HSE_PRIMARY_COURSE      
122463      GCE A LEVEL PROGRAMME YR 2 (NO AIM)
122463      A LEVEL YR 2 TUTORIAL
122463      ICT A2 LEVEL
124338      ELECTROTECHNICAL CERT 2330 C & G
131882      HNC-CIVIL ENGINEERING YR2
135213      TUTORIAL (F1185)
135213      FUNCTIONAL SKILLS (PARENT)
136996      BTEC NATIONAL CERTIFICATE IN SPORT

What I would like to do is to change the way the data is displayed to show the following:

122463,GCE A LEVEL PROGRAMME YR 2 (NO AIM),A LEVEL YR 2 TUTORIAL,ICT A2 LEVEL
124338,ELECTROTECHNICAL CERT 2330 C & G
131882,HNC-CIVIL ENGINEERING YR2
135213,TUTORIAL (F1185), FUNCTIONAL SKILLS (PARENT)
136996,BTEC NATIONAL CERTIFICATE IN SPORT

Preferably I wanted to use SQL to export to CSV

Is there any easy way of doing this usual transact SQL?

Thanks

John

Answer : SQL 2005 Data configuration help

So try this:



1:
2:
3:
4:
5:
select distinct 
t1.[HSE_READER_ID]+', ' AS [HSE_READER_ID], 
stuff((select ',' + [HSE_PRIMARY_COURSE] from [Heri_Student_Courses] 
where [HSE_READER_ID] = t1.[HSE_READER_ID] for xml path('')), 1,1,'') as [HSE_PRIMARY_COURSE] 
from [Heri_Student_Courses] as t1 
Random Solutions  
 
programming4us programming4us