Getting Comma separated Row values using Cursor

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 943
declare emp_name cursor for
select emp_name from employee_master order by emp_name;
declare @emp_names varchar(max);
declare @emp_name varchar(max);

open emp_name

fetch next from emp_name into @emp_name

while @@fetch_status = 0

begin
set @emp_names = isnull(@emp_names + ',', '') + @emp_name
fetch next from emp_name into @emp_name
end

close emp_name
deallocate emp_name

select @emp_names as employee_names

Comments or Responses

Login to post response