top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to concatenate multiple rows into a single text string without using loop?

+1 vote
223 views

Suppose we have a table with the following data:

ClientID    ClientName
3           Sowrabh Malhotra
4           Saji Mon
6           Sajith Kumar
7           Vipin Job
8           Monoj Kumar

We need to concatenate the ClientName column like the following:

Sowrabh Malhotra, Saji Mon, Sajith Kumar, Vipin Job, Monoj Kumar
posted Jun 12, 2015 by Shivaranjini

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Method 1

SELECT ClientName + ', ' 
From ClientMaster 
For XML PATH('')

Method 2

DECLARE @ClientNames VARCHAR(MAX);
SET @ClientNames = '';

SELECT @ClientNames = @ClientNames + IsNull(ClientName + ', ', '')
FROM ClientMaster 
Select @ClientNames
answer Jun 12, 2015 by Manikandan J
Similar Questions
+1 vote

I have data in table A as below

Assetid   attribute   value
    1546    Ins_date   05062011
    1546    status     active
    1546    X          10.4567
    1546    Y          27.56
    1546    size       17
    675     X          4.778
    675     Y          53.676
    675     depth      5
    675     st_date    06092010

I have data as above in table A. This table has many Assetids 1546,675,....etc. attributes might vary for assets.

I want output as below:

assetid  ins_date  status  X        Y       Size  depth  st_date
1546     05062011  active  10.4567  27.56   17    null   null
675      null      null    4.778    53.676  null  5      06092010

I have created Stored procedure, then called in Informatica to achieve this output. However, since i have large volume of data, it is taking much time to load.

Please suggest me other easy and best way to load it.

...