--插入一下临时数据源 with m as( select "张三" name,"语文"course,"89"score uNIOn all select "张三" name,"数学"course,"100"score
--插入一下临时数据源
with m as(
select "张三" name,"语文"course,"89"score uNIOn all
select "张三" name,"数学"course,"100"score union all
select "张三" name,"英语"course,"40"score union all
select "张三" name,"物理"course,"93"score union all
select "张三" name,"地理"course,"95"score union all
select "张三" name,"化学"course,"80"score union all
select "李四" name,"语文"course,"89"score union all
select "李四" name,"数学"course,"100"score union all
select "李四" name,"英语"course,"40"score union all
select "李四" name,"物理"course,"93"score union all
select "李四" name,"地理"course,"95"score union all
select "李四" name,"化学"course,"80"score
)select * into #info from m
select * from #info
--STUFF 拼接
select distinct name,
STUFF((
SELECT "|" + course+"="+score+"分"
FROM #info B
WHERE B.name=A.name FOR XML PATH("")), 1, 1, "") "拼接串"
from #info A
--结束END--
本文标题: SqlServer使用STUFF拼接内容
本文链接: https://lsjlt.com/news/8703.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0