首页 > 解决方案 > 某些 SSMS 版本中显示 SQL Server 错误 493

问题描述

我在 2016 年的 17.7 版(SP2)IntelliSense中收到一条红色波浪线用于以下查询。经过一番研究,原来是错误 493 和严重性 16。查询中的错误是由 where 子句引起的。SSMSMicrosoft SQL Server

询问

SELECT 
  ClientID,
  Person.query('..') AS Person
FROM ClientInfo CROSS APPLY 
  Info_untyped.nodes('/People/Person') AS People(Person)
 where
 Person.exist(
    '/People/Person[@id=5678]') = 1

错误 493

从 nodes() 方法返回的列 'Person' 不能直接使用。它只能用于四种 XML 数据类型方法之一,exist()、nodes()、query() 和 value(),或者用于 IS NULL 和 IS NOT NULL 检查。

SSMS版本 18 和2016 (SP1) 中的相同查询Microsoft SQL Server没有问题。

知道为什么吗?如何解决它。

谢谢

CREATE XML SCHEMA COLLECTION ClientInfoCollection AS 
    '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns="urn:ClientInfoNamespace" 
    targetNamespace="urn:ClientInfoNamespace" 
    elementFormDefault="qualified">
      <xsd:element name="People">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="Person" minOccurs="1" maxOccurs="unbounded">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="FirstName" type="xsd:string" minOccurs="1" maxOccurs="1" />
                  <xsd:element name="LastName" type="xsd:string" minOccurs="1" maxOccurs="1" />
                  <xsd:element name="FavoriteBook" type="xsd:string" minOccurs="0" maxOccurs="5" />
                </xsd:sequence>
                <xsd:attribute name="id" type="xsd:integer" use="required"/>
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>'
    GO
    
    
    CREATE TABLE ClientInfo
    (
      ClientID INT PRIMARY KEY IDENTITY,
      Info_untyped XML,
      Info_typed XML(ClientInfoCollection)
    );
    INSERT INTO ClientInfo (Info_untyped, Info_typed)
    VALUES
    (
      '<?xml version="1.0" encoding="UTF-8"?>
      <People>
        <Person id="1234">
          <FirstName>John</FirstName>
          <LastName>Doe</LastName>
        </Person>
        <Person id="5678">
          <FirstName>Jane</FirstName>
          <LastName>Doe</LastName>
        </Person>
      </People>',
      '<?xml version="1.0" encoding="UTF-8"?>
      <People xmlns="urn:ClientInfoNamespace">
        <Person id="1234">
          <FirstName>John</FirstName>
          <LastName>Doe</LastName>
        </Person>
        <Person id="5678">
          <FirstName>Jane</FirstName>
          <LastName>Doe</LastName>
        </Person>
      </People>'
    )
    
    INSERT INTO ClientInfo (Info_untyped)
    VALUES
    (
      '<?xml version="1.0" encoding="UTF-8"?>
      <People>
        <Person id="4321">
          <FirstName>Jack</FirstName>
          <LastName>Smith</LastName>
        </Person>
        <Person id="8765">
          <FirstName>Jill</FirstName>
          <LastName>Smith</LastName>
        </Person>
      </People>'
    )
    

标签: sql-serverssmsxquery

解决方案


推荐阅读