Technical Article

Return comma seperated values from multiple record

,

It helps you in situaions whenever you wish to create commm seperated values actually originating from multiple records. Say, your query return three records in folloing patter:
Student_Name
=============
Ricky
Adam
Mathew

But, say you wish to have records in following patter:
Student_Name
============
Ricky, Adam, Mathew

That is how it works. Try it...I beleive it will help you  a lot

create procedure sp_return_students
as
set nocount off

/* Declare variable which will store all student name */Declare @StudentName varchar(8000)  

/* Query that will return student names and at the same time concatenate values. /*
select @StudentName = coalesce(@StudentName + ', ', '') + stu_name from tbl_students

/* At last, you just have to define column name that will store values */Select @StudentName As Student_Name

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating