DECLARE @data AS xml = N'<row ACOCLI="00330" ARAGS1="Some description" ACOFIS="01266820248" AEMAIL=" " ACOAGE=" " AANNUL=" " ANOMIG="Some Name"/>'; SELECT @data.value('(row/@ACOCLI)[1]','varchar(6)'), @data.value('(row/@ARAGS1)[1]','varchar(30)'), @data.value('(row/@ACOFIS)[1]','varchar(15)'), @data.value('(row/@AEMAIL)[1]','varchar(6)'), @data.value('(row/@ACOAGE)[1]','varchar(6)'), @data.value('(row/@AANNUL)[1]','varchar(6)'), @data.value('(row/@ANOMIG)[1]','varchar(15)');
SQL 示例。【此方法支持单条xml 反序列化】
DECLARE @data AS xml = '<List Name="Default" Fields=""><Item Id="" UserId="" EmployeeName="许庆贵" WorkNo="3007" ChangeTypeAdd="成手调入" ChangeTypeDel="" InDeptId="PRO0001I.PROP10DD.PROP10DM" InDept="土建室" OutDeptId="" OutDept="" ChangeDate="2007-12-12" Remark="" /> <Item Id="" UserId="" EmployeeName="李晶" WorkNo="3008" ChangeTypeAdd="成手调入" ChangeTypeDel="" InDeptId="PRO0001I.PROP10DD.PROP10DY" InDept="暖通室" OutDeptId="" OutDept="" ChangeDate="2007-12-12" Remark="" /></List>'; SELECT @data.value('(List/Item/@EmployeeName)[1]','varchar(6)'), @data.value('(List/Item/@WorkNo)[1]','varchar(30)'), @data.value('(List/Item/@ChangeTypeAdd)[1]','varchar(15)'), @data.value('(List/Item/@ChangeTypeDel)[1]','varchar(6)'), @data.value('(List/Item/@InDeptId)[1]','varchar(6)'), @data.value('(List/Item/@InDept)[1]','varchar(6)'), @data.value('(List/Item/@ChangeDate)[1]','varchar(15)');