MSSQL2005 XML字段分解

阅读更多

CREATE TABLE [dbo].[T_Model_Component](
[ComponentID] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[ComponentName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[MotorModel] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[Helper] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[Component] [xml] NOT NULL,
CONSTRAINT [PK_T_ComponentItem] PRIMARY KEY CLUSTERED
(
[ComponentID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

select ComponentID,ComponentName,MotorModel,Helper,Component from T_Model_Component

SELECT ComponentID,ComponentName, nref.query('.') ITEM
FROM T_Model_Component
CROSS APPLY Component.nodes('/Data/Item') AS R(nref)
where ComponentID='3'

你可能感兴趣的:(MSSQL2005 XML字段分解)