我有两行数据,我想将它们组合起来像
147000.0000000,49000.00000
之前我尝试连接两个产生这样的列,
如何将两行合并为一行?
答案 0 :(得分:2)
您可以像这样使用FOR XML PATH
<强>查询强>
;WITH Table1 as
(
SELECT 147000.0000000 as TDS_INAMOUNT
UNION ALL SELECT 49000.00000
)
SELECT
STUFF((SELECT ',' + CONVERT(VARCHAR(30),TDS_INAMOUNT)
FROM Table1
FOR XML PATH(''),TYPE
).value('.','VARCHAR(2000)'),1,1,'')
<强>输出强>
147000.0000000 , 49000.00000
如果您想要输出
147000.0000000 in ASKARI HIGH YIELD SCHEME,49000.0000000 in ASKARI EQUITY FUND
使用此功能。
SELECT
STUFF((SELECT ',' + CONVERT(VARCHAR(30),TDS_INAMOUNT) + ' in ' + PRD_Name
FROM Table1
FOR XML PATH(''),TYPE
).value('.','VARCHAR(2000)'),1,1,'')