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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 concanate the values

Author  Topic 

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2003-01-07 : 01:21:11


select folder_id from oit_folders
result
1
3
5
66
77
45
567
765

i need the value to be in this form
1,3,5,66,77,45,567,765

is this possible i read some where but lost it


======================================
Ask to your self before u ask someone

nr
SQLTeam MVY

12543 Posts

Posted - 2003-01-07 : 03:08:45
declare @s varchar(1000)
select @s = coalesce(@s + ',', '') + convert(varchar(20),folder_id)
from oit_folders

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2003-01-08 : 07:22:23


thanks a lot nr... that was cool

can we avoid the varible... if that is eliminate
i need to pass the query as sub query suing in operated

i can run a single query and get the result out

======================================
Ask to your self before u ask someone
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-01-08 : 07:29:02
You could make it into a udf.

create function tt
()
returns varchar(1000)
as
begin
declare @s varchar(1000)
declare @s varchar(1000)
select @s = coalesce(@s + ',', '') + convert(varchar(20),folder_id)
from oit_folders
return @s
end
go

select dbo.tt()


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nr on 01/08/2003 07:35:39
Go to Top of Page
   

- Advertisement -