SQL 服务器 XQuery 语法错误
SQL Server XQuery Syntax Error
我正在为 SQLServer 使用 Serilog Sinks,并使用 this link 遵循数据库模式和 XQuery 语法。但是,当我 运行 在 Navicat 中执行以下查询时,我得到错误。
查询如下:
SELECT
Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="ContactId"])[1]', 'nvarchar(max)') AS ContactId,
Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="FirstName"])[1]', 'nvarchar(50)') AS FirstName,
Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="Surname"])[1]', 'nvarchar(100)') AS Surname,
Properties.value('(/properties/property[@key="cacheKey"])[1]', 'nvarchar(100)') AS CacheKey,
*
FROM Log
WHERE MessageTemplate = 'Contact {@contact} added to cache with key {@cacheKey}'
AND Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="ContactId"])[1]', 'nvarchar(max)') = 'f7d10f53-4c11-44f4-8dce-d0e0e22cb6ab'
错误说明如下:
[Err] 42000 - [SQL Server]Cannot find either column "Properties" or the user-defined function or aggregate "Properties.value", or the name is ambiguous.
任何解决方案或解决方法将不胜感激。
如果日志 table 具有属性列并且其格式为 XML,则您的查询将 运行。
因此,您必须更改列的类型或在查询中将其转换为 XML。
第二种方法看起来像 cast(Properties as xml).value
...
我正在为 SQLServer 使用 Serilog Sinks,并使用 this link 遵循数据库模式和 XQuery 语法。但是,当我 运行 在 Navicat 中执行以下查询时,我得到错误。
查询如下:
SELECT
Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="ContactId"])[1]', 'nvarchar(max)') AS ContactId,
Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="FirstName"])[1]', 'nvarchar(50)') AS FirstName,
Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="Surname"])[1]', 'nvarchar(100)') AS Surname,
Properties.value('(/properties/property[@key="cacheKey"])[1]', 'nvarchar(100)') AS CacheKey,
*
FROM Log
WHERE MessageTemplate = 'Contact {@contact} added to cache with key {@cacheKey}'
AND Properties.value('(/properties/property[@key="contact"]/structure[@type="Contact"]/property[@key="ContactId"])[1]', 'nvarchar(max)') = 'f7d10f53-4c11-44f4-8dce-d0e0e22cb6ab'
错误说明如下:
[Err] 42000 - [SQL Server]Cannot find either column "Properties" or the user-defined function or aggregate "Properties.value", or the name is ambiguous.
任何解决方案或解决方法将不胜感激。
如果日志 table 具有属性列并且其格式为 XML,则您的查询将 运行。
因此,您必须更改列的类型或在查询中将其转换为 XML。
第二种方法看起来像 cast(Properties as xml).value
...