Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query to Concatenate

Author  Topic 

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-01-25 : 04:19:14
I have a table like below.

certid name
1 xxx
1 yyy
1 cvb

now I want to output as xxx,yyy,cvb when i pass input certid=1
I want to get it using a single query statement

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-25 : 04:22:47
select distinct certid, dbo.fnConcat(certid, ',')

select dbo.fnConcat(1, ',')

there are plenty of concat functions here at sqlteam.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-01-25 : 04:53:43
I am using SQL 2005. your reply is not helping me. Please send me the query.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-25 : 05:00:17
My reply is helping you a lot!
Or is your reply/comment a lame excuse to not want to learn SQL? Is this a homework?

Please search SQLTeam. If you are too lazy, click here [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53293[/url]


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-25 : 05:41:27
also
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx


KH

Go to Top of Page

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-01-25 : 06:00:14
See What I meant was that I had to get the result using single simple query and not using any Stored Procedure.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-25 : 06:05:53
No one here ever suggested a stored procedure to you.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-25 : 06:07:21
[code]Declare @out varchar(max)

Select @out = coalesce(@out + ',', '') + [name]
from tbl
where certid = 1

Select @out[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -