0

我有这个sql查询:

SELECT
    [Id],
    [Content]    
FROM 
    [MyTable] with (nolock)
where
    Content is not null
    and (PATINDEX('%"number" : "[0-9]%', Content) > 0
         or PATINDEX('%"number":"[0-9]%', Content) > 0
         or PATINDEX('%"number" :"[0-9]%', Content) > 0
         or PATINDEX('%"number": "[0-9]%', Content) > 0
         --del
         or PATINDEX('%"del":"[0-9]%', Content) > 0
         or PATINDEX('%"del":"[0-9]%', Content) > 0
         or PATINDEX('%"del":"[0-9]%', Content) > 0
         or PATINDEX('%"del":"[0-9]%', Content) > 0
)

在我的服务器上,清除缓存后,返回大约 400 行需要两分钟多的时间,可能是因为我有很多or.

我以这种方式创建了查询,因为Content“:”和“数字”字符串或下一个数字之间是否有空格的列中的“数字”字符串的可能性。

有没有办法减少or条件?

4

1 回答 1

1

试试看

SELECT
    [Id],
    [Content]    
FROM 
    [MyTable] with (nolock)
where
    Content is not null
    and (PATINDEX('%"number":"[0-9]%', replace(Content,' ','')) > 0
         or PATINDEX('%"del":"[0-9]%', replace(Content,' ','')) > 0)

你也可以删除Content is not null部分

于 2017-03-29T17:01:16.020 回答