简体   繁体   English

SQL Server XQuery语法错误

[英]SQL Server XQuery Syntax Error

I'm using Serilog Sinks for SQLServer, and following DB schema and XQuery Syntax using this link. 我正在使用Serilog Sinks for SQLServer,并使用链接遵循DB模式和XQuery语法。 However when I run the following query in Navicat, I get error. 但是,当我在Navicat中运行以下查询时,出现错误。

Here's the query: 这是查询:

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' 

Here is the error statement: 这是错误声明:

[Err] 42000 - [SQL Server]Cannot find either column "Properties" or the user-defined function or aggregate "Properties.value", or the name is ambiguous. [Err] 42000-[SQL Server]找不到列“属性”或用户定义的函数或聚合“ Properties.value”,或者名称不明确。

Any solution or workaround would be highly appreciated. 任何解决方案或解决方法将不胜感激。

Your query would run if Log table had Properties column and its format was XML. 如果“日志”表具有“属性”列且其格式为XML,则将运行查询。

So, you have to change the type of a column or cast it as XML in a query. 因此,您必须更改列的类型或在查询中将其转换为XML。

Second approach would look like cast(Properties as xml).value ... 第二种方法看起来像cast(Properties as xml).value ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM