Monday, 20 May 2019

Convert multiple rows into one with comma as separator

Introduction:-

in this article we will learn how to convert multiple row into one comma separator.

Example:-



I have table that contain the skill data . now convert it comma separated form.



Synatx:-

1. 
Declare @tmp varchar(250)

SET @tmp = ''
select @tmp = @tmp + ColomnName + ', ' from TableName
select SUBSTRING(@tmp, 0, LEN(@tmp))


2.
select
stuff((
SELECT ',' + ColomnName 
FROM     TableName
for xml path('')
1.      ),1,1,'') as name_csv






No comments:

Post a Comment

What is Agile,advantage and disadvantages

Introduction:- It is a software development life cycle used for software development, that is characterized by the division of tasks in...