Thursday, May 14, 2009

Creating Comm Separated string Using Select Statement.

We can Create comma separated string in Sql using simple select statement.

here is the sql script for this task.


declare @AllUsers varchar(500)
set @AllUsers=''
Select @AllUsers=@AllUsers+cast([ID] as varchar(20))+',' from User_mst
print substring(@AllUsers,0,len(@AllUsers))

Thanks.