-- 建表
CREATE TABLE #T
(
a VARCHAR(10),
b VARCHAR(10),
c VARCHAR(10)
)
INSERT INTO #T VALUES('1','2','3')
INSERT INTO #T VALUES('6','5','4')
INSERT INTO #T VALUES('7','8','0')
-- 查看表
SELECT * FROM #T
1 2 3
6 5 4
7 8 0
-- 纵向合并
SELECT ''+a FROM #T FOR XML PATH('')
SELECT ''+b FROM #T FOR XML PATH('')
SELECT ''+c FROM #T FOR XML PATH('')
167
258
340
-- 横向合并,同时进行排序
SELECT a,b,c,(SELECT ''+x FROM (VALUES(a),(b),(c)) AS tmp(x) ORDER BY x FOR XML PATH('') ) as concanate FROM #T
1 2 3 123
6 5 4 456
7 8 0 078
-- 弃表
DROP TABLE #T