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)
 Query result to a single row per GUID

Author  Topic 

gtaipalus
Starting Member

6 Posts

Posted - 2009-08-10 : 14:47:11
I have a SQL 2005 table that looks like this (2 columns, multiple rows per patient):
PatientID Allergy
---------- --------
1 Fish
1 Peanuts
2 Wheat
2 Dairy
3 Coconut

I need to create a query or temp table to display the records like this (2 columns and 1 row for each patient):
PatientID Allergy
---------- --------
1 Fish, Peanuts
2 Wheat, Dairy
3 Coconut

I found a similar posting here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=127132
However this solution moves all PatientID's and Allergies to a single row and single column, instead of a separate row for each patient. Any idea's are appreciated.
Thank you!

GT

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-08-10 : 15:02:21
Read through this post (as well as some the contained links) for a solution:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53293

EDIT:
Alternative approach and a lot more discussion here:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Be One with the Optimizer
TG
Go to Top of Page

gtaipalus
Starting Member

6 Posts

Posted - 2009-08-10 : 15:30:35
TG, thank you! I found a solution at one of your links that seems to work.

GT
Go to Top of Page
   

- Advertisement -