sql >> Database >  >> RDS >> Sqlserver

Hoe XML-kolom in SQL Server 2008 te lezen?

with xmlnamespaces('http://schemas.microsoft.com/office/infopath/2003/myXSD/2014-03-29T09:41:23' as my)
select M.XMLData.value('(/my:myFields/my:field1/text())[1]', 'int') as field1,
       M.XMLData.value('(/my:myFields/my:field2/text())[1]', 'int') as field2,
       M.XMLData.value('(/my:myFields/my:field3/text())[1]', 'bit') as field3,
       M.XMLData.value('(/my:myFields/my:FormName/text())[1]', 'datetime') as FormName,
       (
         select ','+R.X.value('text()[1]', 'nvarchar(max)')
         from M.XMLData.nodes('/my:myFields/my:Repeating') as R(X)
         for xml path(''), type
       ).value('substring(text()[1], 2)', 'nvarchar(max)') as Repeating
from XMLMain as M

Resultaat:

field1      field2      field3 FormName                Repeating
----------- ----------- ------ ----------------------- -----------------------
1           2           1      2014-04-01 15:11:47.000 hi,hello,how are  you?



  1. INSERT ... OP DUPLICATE KEY UPDATE met WAAR?

  2. Wat is er precies gebeurd met de indexeringsoperatie?

  3. MariaDB Backup &PostgreSQL in de cloud - ClusterControl Release 1.6.1

  4. mysql/php is dit een veilige manier om verbinding te maken met mysql DB?