Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Convert Table to Delimited List

Posted on 2011-10-13
7
Medium Priority
?
189 Views
Last Modified: 2012-05-12
I have a table that looks like this: http://screencast.com/t/rcPtDTfK05

I'd like to create a view, based on this table that looks like this: http://screencast.com/t/eK699ixc226V

Using MS SQL 2005

0
Comment
Question by:stevengraff
  • 3
  • 2
  • 2
7 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36962493
I am unable to load the images you linked to, can you attach them to the post directly?
0
 
LVL 11

Author Comment

by:stevengraff
ID: 36962506
How would I do that? "Paste" or ctrl-v doesn't seem to work.
0
 
LVL 9

Expert Comment

by:sachinpatil10d
ID: 36962511
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:sachinpatil10d
ID: 36962604
run this query
SELECT p1.CustNo,
       ( SELECT COlor + ','
           FROM TblName p2
          WHERE p2.CustNo = p1.CustNo
          ORDER BY CustNo
            FOR XML PATH('') ) AS Products
      FROM TblName p1
      GROUP BY CustNo ;

Open in new window

0
 
LVL 9

Accepted Solution

by:
sachinpatil10d earned 2000 total points
ID: 36962626
output eliminating last comma


select CustNo, left(COlors,len(COlors)-1) COlors from 
(SELECT p1.CustNo,
       ( SELECT COlor + ','
           FROM TblName p2
          WHERE p2.CustNo = p1.CustNo
          ORDER BY CustNo
            FOR XML PATH('') ) AS COlors
      FROM TblName p1
      GROUP BY CustNo ) t;

Open in new window

0
 
LVL 28

Expert Comment

by:strickdd
ID: 36962638
At the bottom, below the comment box, there is a link to add "File", "Code", "Image", or "Screenshot"
0
 
LVL 11

Author Closing Comment

by:stevengraff
ID: 36962674
Final incarnation (to remove extra spaces between color and comma, using rtrim):

select CustNo, left(COlors,len(COlors)-1) COlors from
(SELECT p1.CustNo,
       ( SELECT rtrim(COlor) + ', '
           FROM products p2
          WHERE p2.CustNo = p1.CustNo
          ORDER BY CustNo
            FOR XML PATH('') ) AS COlors
      FROM products p1
      GROUP BY CustNo ) t;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

578 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