SELECT DISTINCT StateID, (SELECT CAST(ColorID as varchar)+'|' +ColorDesc+'|' FROM urTable n WHERE a.stateid = n.stateid FOR XML PATH('') )
from urTable a
Main Topics
Browse All Topicsi have a table in below mentioned format:
StateID ColorID ColorDesc
21 5 Green
21 18 Red
21 11 A
22 5 Green
22 19 B
23 55 M
27 100 Cofee
27 99 Blue
etc..
I want to stored procedure in MS Sql Server 2005 which should return the output in below format:
sateid RequiredColorDetails
21 5|Green|18|Red|11|A
22 5|Green|19|B
23 55|M
27 100|Cofee|99|Blue
etc..
Please help me.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-07-05 at 12:04:47ID: 24780960
you need the "group_concat" emulation in sql server, with the XML trick: 008/11/emu lating-mys qls- groupc oncat-func tion.html
http://blog.shlomoid.com/2