How do you read XML column in SQL Server 2008?

后端 未结 3 483
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 14:39

I have never used XML in SQL Server 2008, I need to extract a list of customers into a variable table how do you do it?

Given that I have a column called Custo

3条回答
  •  -上瘾入骨i
    2020-11-30 15:31

    Try something like this:

    SELECT
       Cust.value('(ItemId)[1]', 'int') AS 'ItemID',
       Cust.value('(Value)[1]', 'Varchar(50)') AS 'Customer Name'
    FROM
       dbo.Sales.CustomerList.nodes('/ArrayOfCustomers/Customer') AS AOC(Cust)
    

    That should give you an output something like this:

    ItemID  Customer Name
       1         Mr Smith
       2         Mr Bloggs
    

提交回复
热议问题