父表ID查询子表 所属name字符拼接 for xml path
Declare@tTable?
(
IDint,
FNamevarchar(20),
CNamevarchar(20),
CAgevarchar(20)
)
InsertInto@t
select 1,'吳亮','吳1','3歲'Union
select 1,'吳亮','吳2','5歲'Union
select 1,'吳亮','吳3','9歲'Union
select 4,'麥大偉','麥1','3歲'Union
select 4,'麥大偉','麥2','5歲'Union
select 6,'張思','張1','3歲'
?
SelectID,FName,CName=Stuff((Select','+CNameFrom@tWhereID=T.IDForxmlpath('')),1,1,''),
CAge=Stuff((Select','+CAgeFrom@tWhereID=T.IDForxmlpath('')),1,1,'')
From@tTGroupbyid,FName
?
?
??
?
select id,name,Ctypeid,ISNULL(STUFF((select ','+name from A00006 where Id in(select Aid from A00010 where Bid=c.Id) for xml path('')) ,1,1,'' ),'') temp? from A00009 c
?
轉載于:https://www.cnblogs.com/konghao/p/3696230.html
總結
以上是生活随笔為你收集整理的父表ID查询子表 所属name字符拼接 for xml path的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 腾讯最新专利曝光!未来网上聊天可发送有声
- 下一篇: Ecos笔记--2014/5/3