February 17, 2005 at 11:43 pm
Hi friends,
Table
Id value
-- -----
1 a
1 b
1 c
2 d
I need a query to print out value as if I pass id as 1
field1
------
a,b,c
Using only query not SP.
Thanks in advance
February 18, 2005 at 12:33 am
declare @var nvarchar(150)
set @var = ''
select @var = @var + value + "," from table where id = 1
print @var
My Blog:
February 18, 2005 at 3:58 am
declare @value varchar(100)
select @value =coalesce(@value +',','')+value from t where id =1
select @value
Helen
--------------------------------
Are you a born again. He is Jehova Jirah unto me
February 18, 2005 at 6:43 am
Helen's suggestion works but it is an undocumented feature that may not continue with future versions of SQL Server. My suggestion is to create a function that loops through the records and returns a string of the values.
If the phone doesn't ring...It's me.
February 18, 2005 at 7:38 am
I don't think this is undocumented. This technique is called aggregate concatenation and widely used. However, there do exists problems with it which are described here:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;287515
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply