OpenQuery where子句使用多个like

时间:2019-01-31 00:40:31

标签: sql sql-server

我正在尝试使用多个Where子句NOT LIKE运行Openquery,但给我错误

  

“错误:MALFORMED_QUERY,第15行:第16列意外错误:错误:   喜欢”。

我要运行的是这样的

SELECT  *   from openquery(Server, 'Select Id
        , BodyLength
        , ContentType
        , CreatedById
        , CreatedDate
        , Description
        , IsPrivate
        , LastModifiedById
        , LastModifiedDate
        , Name
        , OwnerId
        , ParentId
        from Attachment
        where LastModifiedDate > 2018-11-16T00:00:00Z
        and (Name NOT like (''SML -%'') and
        Name NOT like (''EARLY -%'') and
        Name NOT like (''DELAYED -%'') and
        Name NOT like (''CLOSED -%'') and
        Name NOT like (''CLOSURE -%'') and
        Name NOT like (''OUTAGE -%'') and
        Name NOT like (''MISC -%'') and
        Name NOT like (''TIME AS A CONTROL%'') and
        Name NOT like (''TEMPORARY -%''))
        order by Id
        LIMIT 10000') x

我要排除的是按名称开头的所有记录。 当未按名称排除时,它运行平稳,但我确实需要它。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

问题可能出在您的日期常数,而不是like。它需要定界符:

where LastModifiedDate > ''2018-11-16T00:00:00Z'' and
      (Name NOT like ''SML -%'' and
       Name NOT like (''EARLY -%'') and
       . . .
      )