SQL Server相当于WM_CONCAT函数 [英] SQL Server equivalent of WM_CONCAT function
本文介绍了SQL Server相当于WM_CONCAT函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b b
什么是SQL Server等效的WM_CONCAT?
What is the SQL Server equivalent of WM_CONCAT?
推荐答案
你没有一个等效的函数,你仍然可以模拟(使用 CROSS APPLY
和 FOR XML PATH('')
)。示例,
You don't have an equivalent function for that, but you can still simulate (make useof CROSS APPLY
and FOR XML PATH('')
). example,
USERID ADDRESSLINE1
==========================
1 First Street
1 Second Street
2 32th Street
2 24th Street
2 25th Street
会导致
USERID ADDRESSLIST
============================
1 First Street, Second Street
2 32th Street, 24th Street, 25th Street
使用此查询:
SELECT a.UserID,
SUBSTRING(d.Addresses,1, LEN(d.Addresses) - 1) AddressList
FROM
(
SELECT DISTINCT UserID
FROM tableName
) a
CROSS APPLY
(
SELECT [AddressLine1] + ', '
FROM tableName AS B
WHERE A.UserID = B.UserID
FOR XML PATH('')
) D (Addresses)
这篇关于SQL Server相当于WM_CONCAT函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文