Concatenating xml values when selecting by XQuery in T-SQL
This is my sample XML: <root> <element> <subelement> <value code="code1">value1</value> <value code="code2">value2</value> </subelement> </element> </root> And this is my test query: DECLARE @tempTable TABLE ( ValueCode nvarchar(MAX), Value nvarchar(MAX) ) DECLARE @xml XML select @xml = cast(c1 as xml) from OPENROWSET (BULK 'C:\test.xml', SINGLE_BLOB) as T1(c1) INSERT INTO @tempTable SELECT Tbl.Col.value('subelement[1]/@code', 'NVARCHAR(MAX)'), Tbl.Col.value('subelement[1]', 'NVARCHAR(MAX)') FROM @xml.nodes('//element') Tbl(Col) SELECT * FROM @tempTable The query, when executed, gives out a