问题描述
嗨
我有内表如
CommentID FirstName
15 Davidson Lincoln
15 JohnFirstNameJoI
15 testf 1
17 Davidson Lincoln
17 fp1
17 JohnFirstNameJoI
17 testf p1
18 Davidson Lincoln
18 html
18 JohnFirstNameJoI
19 Davidson Lincoln
19 html
19 JohnFirstNameJoI
现在我希望以下列格式
CommentID FirstName
15 Davidson Lincoln,JohnFirstNameJoI,testf
17 Davidson Lincoln ,fp1,JohnFirstNameJoI p1,testf p1
18 Davidson Lincoln,html,JohnFirstNameJoI
19 Davidson Lincoln ,html,JohnFirstNameJoI
我的意思是我想在commentid的基础上在单格中命名。请给我任何解决方案离开。
感谢和问候
Rahul Sharma
Hi
I have inner table like
CommentID FirstName
15 Davidson Lincoln
15 JohnFirstNameJoI
15 testf1
17 Davidson Lincoln
17 fp1
17 JohnFirstNameJoI
17 testf p1
18 Davidson Lincoln
18 html
18 JohnFirstNameJoI
19 Davidson Lincoln
19 html
19 JohnFirstNameJoI
now i want this in following format
CommentIDFirstName
15Davidson Lincoln,JohnFirstNameJoI,testf
17Davidson Lincoln,fp1,JohnFirstNameJoIp1,testf p1
18Davidson Lincoln,html,JohnFirstNameJoI
19Davidson Lincoln,html,JohnFirstNameJoI
I mean i wanna first name in single cell on the basis of commentid.Please provide me any solution.
Thank and Regards
Rahul Sharma
推荐答案
SELECT C.CommentID as CommentID,
STUFF(( SELECT ',' + Sub.FirstName as [text()]
FROM Consumer Sub Where Sub.CommentID = C.CommentID
FOR XML PATH ('')),1,1,'')
as FirstNames
From Consumer C
这篇关于如何在group by的单元格中设置整列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!