先看下数据表:
详细XML:
<Roles>
<Role>CA</Role>
<Role>CentralSite</Role>
<Role>DC</Role>
</Roles>
查询1:
Select Roles.value('(/Roles/Role)[1]', 'nvarchar(20)')
From dbo.MachineConfigs
结果:
查询2:
select (select Roles from MachineConfigs whereID='F16C7025-4E67-4F7F-814D-04D6B5B9387C' ).query('(/Roles/Role[1])')
结果: