Solved

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

Posted on 2013-05-30
2
336 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
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help creating a stored procedure 4 64
SQL Server 2012 express 24 41
SQL Backup skipping a few tables 7 52
Find results from sql within a time span 11 48
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…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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