Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ASM
i have data like bellow,

id         name         add     dateEnterd
1         ab             test     23-8-1988
1         ab             test     23-8-1989
1         ab             test     23-8-1990
1         ab             test     22-5-1999

how do i get somthing like

id         name         add     dateEnterd
1         ab             test     23-8-1988,23-8-1989,23-8-1990,22-5-1999
Posted
Comments
Karthik_Mahalingam 6-Jan-14 4:52am    
in sql or linq c# ??

 
Share this answer
 
If i am understanding your question correctly you require SQL statement to get data comma separated
SQL
DECLARE @list VARCHAR(MAX)
SELECT @list = COALESCE(@list+',' ,'') + Name
FROM tablename where Id=@id
SELECT @list
 
Share this answer
 
SQL
declare @str varchar(1000)

SELECT @str= coalesce(@str + ', ', '') + a.X FROM (SELECT CONVERT(varchar(100),dateEnterd) AS X  from TableName where ID=1 and name='ab' and [add]='test') a

SELECT TOP 1 ID,NAME,[add],@str FROM TableNAme WHERE ID=1 and name='ab' and [add]='test' ORDER BY ID ASC


Please refer this link bellow
Column Values as Comma Separated String[^]
 
Share this answer
 
v3
Comments
abhishekgoletar 6-Jan-14 5:19am    
thanx for replay i want to do it with c# not with sql as i m using llblgen so this query want be possible
SQL
my table commadate having below data 

id	name	add	dateEnterd
1	ab	test	1988-08-23
1	ab	test	1989-08-23
1	ab	test	1990-08-23
1	ab	test	1991-05-01




SELECT ROW_NUMBER() OVER(order by dateEnterd asc)as ID,dateEnterd INTO #TempcomDate
FROM commadate

DECLARE @SR INT
DECLARE @ID INT
DECLARE @strDate NVARCHAR(MAX)

SET @SR=1
SET @ID=(SELECT MAX(ID) FROM #TempcomDate)
SET @strDate=''

WHILE(@SR<=@ID)
BEGIN
IF(@SR>1)BEGIN SET @strDate+=',' END
SET @strDate+=CONVERT(NVARCHAR(50), (SELECT dateEnterd FROM #TempcomDate WHERE ID=@SR))
SET @SR=@SR+1
END
SELECT DISTINCT id,name,[add],@strDate AS dateEnterd from dbo.commadate 
DROP TABLE #TempcomDate


O/P
id	name	add	dateEnterd
1	ab	test	1988-08-23,1989-08-23,1990-08-23,1991-05-01
 
Share this answer
 
v2
Comments
abhishekgoletar 6-Jan-14 5:54am    
thx but i have mention not using sql,i want to do it in c# lets assume i have datatable with that data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900