Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comma Separated List

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Hello all --

Before I go spending too much time programming a solution for this, I was wondering if there's a SQL solution...

Let's say I have a table that looks like this:

SVP VPO
52 1
52 1
52 2
52 2

My end product for my app needs to be a comma separated list of VPOs that have SVP=52 (i.e. 1,2)

So if I ask:
SELECT VPO FROM table WHERE SVP = 52 GROUP BY VPO

then I get:
1
2

Is there a way I can get:
1,2

??

SQL Server is my DBMS, if that helps at all.

Thanks! :)
paul
penny1.gif
penny1.gif
 
If you don't have too many varieties for VPO within SVP, this method might work:

Select SVP,
Max(case when VPO = 1 then 1 else 0 end),
Max(case when VPO = 2 then 2 else 0 end),
Max(case when VPO = 3 then 3 else 0 end),
ETC. {for as many as you need}
From Table
Group by SVP


If your DBMS returns CSV files, the output is fine. If not, you'll have to put commas in. I've done this with up to 35 values for my comparable SVP column.
 
mmmm... yes, but then if anything in your table changes, then you have to go through and update every single instance of such statements. :-(

I'm thinking I'll just get my result set and parse it with code. Less maintenance, and not terribly inefficient.

Thanks, though. :)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top