Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-30
2
Medium Priority
?
354 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 2000 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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