Solved

Stored procedure to retreive data in MS Sql Server

Posted on 2009-07-05
2
191 Views
Last Modified: 2012-05-07
i 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.
0
Comment
Question by:ram27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 24780960
you need the "group_concat" emulation in sql server, with the XML trick:
http://blog.shlomoid.com/2008/11/emulating-mysqls-groupconcat-function.html
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 300 total points
ID: 24781069
SELECT DISTINCT StateID, (SELECT CAST(ColorID as varchar)+'|' +ColorDesc+'|' FROM urTable n WHERE a.stateid = n.stateid FOR XML PATH('') )
from urTable a
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question