1
我正在尝试查询XML文件以提取用户/许可证信息。我似乎被卡住了。下面是我的数据集:SQL从XML查询
<?xml version="1.0" encoding="UTF-16"?>
<Users>
<User>
<UserName>Elise</UserName>
<IsConnected>1</IsConnected>
<Modules>
<Module>
<KeyType>LOGISTICS-LTD</KeyType>
<KeyDesc>Limited Logistics User</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP-ADDONS</KeyType>
<KeyDesc>SAP AddOns</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP0000007050</KeyType>
<KeyDesc>Workflow</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
</Modules>
</User>
<User>
<UserName>alice</UserName>
<IsConnected>0</IsConnected>
<Modules>
<Module>
<KeyType>BASIS0001000061</KeyType>
<KeyDesc>Magma Credit Cards</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>LOGISTICS-LTD</KeyType>
<KeyDesc>SAP Business One Limited Logistics User</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP-ADDONS</KeyType>
<KeyDesc>SAP AddOns</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP0000007050</KeyType>
<KeyDesc>Workflow</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
</Modules>
</User>
</UserS>'
我想要实现是一个SQL SELECT返回这样的数据:
UserName KeyType KeyDesc
Elise LOGISTICS Limited Logistics
Elise SAP-ADDONS SAP AddOns
Elise SAP0000007050 Workflow
Alice BASIS0001000061 Magma Credit Card
Alice LOGISTICS Limited Logistics
Alice SAP-ADDONS SAP AddOns
Alice SAP0000007050 Workflow
,但是这是我一直被退回:
UserName KeyType KeyDesc
NULL LOGISTICS Limited Logistics
NULL SAP-ADDONS SAP AddOns
NULL SAP0000007050 Workflow
NULL BASIS0001000061 Magma Credit Card
NULL LOGISTICS Limited Logistics
NULL SAP-ADDONS SAP AddOns
NULL SAP0000007050 Workflow
我不能找出如何从另一个节点返回UserName,任何帮助将是伟大的!以下是我的SQL:
DECLARE @xmlData XML
set @xmlData='<?xml version="1.0"?>
<Users>
<User>
<UserName>Elise</UserName>
<IsConnected>1</IsConnected>
<Modules>
<Module>
<KeyType>LOGISTICS-LTD</KeyType>
<KeyDesc>Limited Logistics User</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP-ADDONS</KeyType>
<KeyDesc>SAP AddOns</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP0000007050</KeyType>
<KeyDesc>Workflow</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
</Modules>
</User>
<User>
<UserName>alice</UserName>
<IsConnected>0</IsConnected>
<Modules>
<Module>
<KeyType>BASIS0001000061</KeyType>
<KeyDesc>Magma Credit Cards</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>LOGISTICS-LTD</KeyType>
<KeyDesc>SAP Business One Limited Logistics User</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP-ADDONS</KeyType>
<KeyDesc>SAP AddOns</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
<Module>
<KeyType>SAP0000007050</KeyType>
<KeyDesc>Workflow</KeyDesc>
<DbType>MSS</DbType>
<BitmaskOfLicensedModules>-255</BitmaskOfLicensedModules>
<ReferingCount>0</ReferingCount>
<InstallNo>0020534918</InstallNo>
</Module>
</Modules>
</User>
</Users>'
SELECT
ref.value('UserName[1]', 'NVARCHAR(100)') AS 'User' ,
ref.value('KeyType[1]', 'NVARCHAR (100)') AS 'Type' ,
ref.value('KeyDesc[1]', 'NVARCHAR (100)') AS 'Desc'
FROM @xmlData.nodes('/Users/User/Modules/Module')
xmlData(ref)
什么是您当前的查询,所以我们可以自己调试查询?听起来像一个XPath问题,可以通过一些导航属性来解决。 –
嘿,对不起,忘记发布我的查询!我现在编辑了这篇文章。 – JPC12