为什么不是&#34; NOT(<search_condition>)&#34;在定义中列出?</search_condition>

时间:2014-06-27 17:33:21

标签: tsql

根据测试,WHERE NOT是有效的SQL语法

 where  not ( x = 10  y > 5 )

但是,我不遵循定义:

对我来说,搜索条件的T-SQL定义似乎不允许生成NOT ( <search_condition> )

规范/文档使得看起来像一元否定的唯一合法目标是谓词。要产生not ( <search_condition> ),看起来这需要声明是连接或分离的右侧......规范是不正确的,还是我错过了产生这种方法的方法?

< search_condition > ::= 
    { [ NOT ] <predicate> | ( <search_condition> ) } 
    [ { AND | OR } [ NOT ] { <predicate> | ( <search_condition> ) } ] 
[ ,...n ] 
<predicate> ::= 
    { expression { = | < > | ! = | > | > = | ! > | < | < = | ! < } expression 
    | string_expression [ NOT ] LIKE string_expression 
  [ ESCAPE 'escape_character' ] 
    | expression [ NOT ] BETWEEN expression AND expression 
    | expression IS [ NOT ] NULL 
    | CONTAINS 
  ( { column | * } ,'< contains_search_condition >') 
    | FREETEXT ( { column | * } ,'freetext_string') 
    | expression [ NOT ] IN (subquery | expression [ ,...n ] ) 
    | expression { = | < > | ! = | > | > = | ! > | < | < = | ! < } 
  { ALL | SOME | ANY} (subquery) 
    | EXISTS (subquery)     } 

2 个答案:

答案 0 :(得分:1)

NOT在两个部分的方括号中列出,这意味着它是可选的。

如果我们扩展这个:

< search_condition > ::= 
    { [ NOT ] <predicate> | ( <search_condition> ) } 
    [ { AND | OR } [ NOT ] { <predicate> | ( <search_condition> ) } ] 
[ ,...n ] 

,删除一些方括号和可能的内容,我们得到:

< some_search_condition > ::= { NOT ( <search_condition> ) }

你的字符串匹配。

答案 1 :(得分:0)

Transact-SQL Syntax Conventions

  

[](括号)可选的语法项。不要键入括号。

该语法链接位于页面上,其定义为
Search Condition (Transact-SQL)

  

Transact-SQL语法约定

你是什么意思不支持不? 发布失败的查询。

运行得很好

 select nativeMD5
   from docSVsys 
   join docSVtext 
     on docSVtext.fieldID = 110 
    and docSVtext.sID = docSVsys.sID
  where not (docSVsys.sID = 10 or docSVsys.sID = 11)