Solved

SQL server 2005, concatenate groups e.g OrderNo1 : OrderID 1,2,4.

Posted on 2013-05-30
2
343 Views
Last Modified: 2013-05-30
Hi, I have a table

OrderNo  OrderID
OrderNo1 1
OrderNo1 2
OrderNo1 3
OrderNo2 4
OrderNo2 5
How in SQL 2005 will I be able to , per OrderNo, get a concatenated list of IDs? i.e.

OrderNo1  1,2,3
OrderNo2  4,5
0
Comment
Question by:jxharding
[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 7

Accepted Solution

by:
Ross Turner earned 500 total points
ID: 39207648
Hi

Try this, i created and example with the link below

http://sqlfiddle.com/#!3/ac5a9/8

select distinct 
Orderno,
STUFF(
               (SELECT      ',' + Cast(Order_ID.OrderID as varchar(30))
               FROM      test AS Order_ID
               WHERE      Order_ID.OrderNo = test.OrderNo
                    
               FOR XML PATH('')), 1, 1, '') AS OrderID
from test

Open in new window

0
 

Author Closing Comment

by:jxharding
ID: 39207723
Brilliant!! thank you!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
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…

630 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