Comma separated values [Resolved]

Posted by Jpchoudhari under Sql Server on 10/11/2011 | Points: 10 | Views : 1257 | Status : [Member] | Replies : 4
Hi,

I am getting below output from my sql query (select date from table)

16-08-2011
08-08-2011
03-08-2011
03-08-2011
11-08-2011
25-08-2011
26-08-2011
13-09-2011
23-09-2011
26-09-2011
07-10-2011

and I want it like 16-08-2011,08-08-2011....

How to get this??

Kind Regards,
Jay



Responses

Posted by: SheoNarayan on: 10/11/2011 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
Hi Jpchoudhari,

Read this code snippet from Madhu

http://www.dotnetfunda.com/codes/code1317-to-return-comma-separated-column-values-.aspx

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.biswas on: 10/12/2011 [Member] Platinum | Points: 25

Up
0
Down
Try this

Declare @t table( dt date)

Insert Into @t
Select '08-18-2011' Union All
Select '08-08-2011' Union All
Select '08-03-2011' Union All
Select '08-03-2011' Union All
Select '11-08-2011'
Select
ConcatenatedDates = Stuff((Select
',' + Convert(varchar(10),dt,110)
From @t
For Xml Path('')
),1,1,'')

/*
ConcatenatedDates
08-18-2011,08-08-2011,08-03-2011,08-03-2011,11-08-2011
*/


Best Regards,
Niladri Biswas

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi Jpchoudhari,

DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + Date FROM Table
SELECT @listStr

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Mark these also answer if it helpful to you..That helps others who search the same...

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response