Solved

Equivalent for wm_concat in SQL Server

Posted on 2011-09-19
5
2,734 Views
Last Modified: 2012-05-12
Is there an equivalent function in SQL Server for the oracle wm_concat.  I need to make two rows into one but cant seem to find a simple function in SQL that will allow this.
0
Comment
Question by:Rhonda Carroll
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 36560579
Hi,

You could use FOR XML PATH, like

SELECT ID, STUFF((SELECT ', '+t2.name AS[text()] FROM table1 t2 WHERE t2. ID =t1. ID FOR XML PATH('')), 1, 2, '') AS list
FROM table1 t1
GROUP BY t1.ID

/peter
0
 

Author Comment

by:Rhonda Carroll
ID: 36560712
This works for my character field there is a lot of syntax .  Is there a way to do it for a numeric field.  Ideally I would like to just have the string comma delimited if possible
0
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 36560788
Then you have to convert the numeric field to a char field.

SELECT ID, STUFF((SELECT ', '+CONVERT(varchar(10), t2.numericvalue) AS[text()] FROM table1 t2 WHERE t2. ID =t1. ID FOR XML PATH('')), 1, 2, '') AS list
FROM table1 t1
GROUP BY t1.ID
0
 

Author Comment

by:Rhonda Carroll
ID: 36561023
That works,  I am almost there.  Is there a way to get rid of the >,6.60000</T><T>,79.20000</T> ... I would like to get the values separated by the comma only .. eliminating the </T><T>,
0
 

Author Comment

by:Rhonda Carroll
ID: 36561132
never mind figured it out, just removed the as piece from the string
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Backup & Restore 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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now