码迷,mamicode.com
首页 > 数据库 > 详细

SQL SERVER FOR XML PATH合并字符串

时间:2016-01-11 18:09:53      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

两种方式,效率立竿见影

------------------------------------------------
SET STATISTICS TIME ON
DECLARE  @OrderStr  NVARCHAR(max) = ‘‘;

SELECT @OrderStr += a.SerialNumber+,
FROM dbo.WithdrawalsLog a

SET STATISTICS TIME OFF
------------------------------------------------

SET STATISTICS TIME ON

DECLARE  @OrderStr  NVARCHAR(max) = ‘‘;

SET @OrderStr = (
SELECT a.SerialNumber+,
FROM dbo.WithdrawalsLog a
FOR XML PATH(‘‘)
)

SET STATISTICS TIME OFF
------------------------------------------------

 

如果要获取某个表的字段,并把它拼接成一个字符串,那这个方法再好不过了:

SELECT bankcode+,+bankname+;   FROM BankInfo FOR XML PATH(‘‘)

 

 

懒得写了,看不懂的看这里: 

http://www.cnblogs.com/doubleliang/archive/2011/07/06/2098775.html

 

SQL SERVER FOR XML PATH合并字符串

标签:

原文地址:http://www.cnblogs.com/DBArtist/p/FORXML.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!