question

Chris 2 avatar image
Chris 2 asked

MS SQL 2012 FOR XML combine 2 fields to 1

Hi, Running MS SQL 2012 on Windows 2008R2. How to combine 2 fields into one in FOR XML PATH. Tried few options like after type.value('((/Label + Value)[1].'varchar(max), 1, 1, '')....nothing work. Any hint? thanks SELECT .... ,CAST(STUFF((SELECT DISTINCT '|' + Label + ',' + Value FROM dbo.b b WITH(NOLOCK) WHERE a.ID = b.ID ORDER BY '|' + Label + ',' + Value FOR XML PATH (''), root('Label'), type).value('/Label[1]','varchar(max)'), 1, 1, '') AS VARCHAR(max)) AS 'Name,Value' FROM [dbo].[a] a WITH(NOLOCK)
mssql2012
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Can you post example input data and expected output?
0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.