SQL Server中的组合字符串 [英] Combination String in SQL Server
问题描述
您好,所有专家,
我有1张桌子(Tbl1).它具有一些字段(TblCode,ItemCode,Name,Name1,qty,Amount)
数据显示如下:
1 I0001面板B 1100
1 I0002鼠标B 1 200
1 I0003 A4纸C 1200
1 I0004键D 1 10
我想将Name1列合并为一个字符串.根据示例,它将 BCD
注意:
如果Name1相同,则仅选择1.以一个示例为例,B具有2行,但仅选择1
我应该像示例一样结合什么查询?
谢谢
TONY
Hi all experts,
I have 1 table(Tbl1). it has some fields(TblCode,ItemCode,Name,Name1,qty,Amount)
the data display like this:
1 I0001 Panel B 1 100
1 I0002 Mouse B 1 200
1 I0003 A4Paper C 1 200
1 I0004 Key D 1 10
i want to combine Column Name1 into one string. base on example, it will BCD
Note:
if Name1 is the same, choose only 1. base one example, B has 2 row, but select only 1
What query should i combine string like example?
Thanks
TONY
推荐答案
SELECT '' + Name1 from (select distinct Name1 FROM tbl1) as tbl
FOR XML PATH('')
这篇关于SQL Server中的组合字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!