是否全文搜索CONTAINS子句总是被评估? [英] Is Full Text Search CONTAINS clause always evaluated?

查看:123
本文介绍了是否全文搜索CONTAINS子句总是被评估?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在下面的例子中避免错误空或全空白全文谓词

  DECLARE @SearchText VARCHAR(1000); 
SET @SearchText =''

SELECT * FROM myTable
WHERE
/ *
某些转换

* /

@SearchText =''


@SearchText<>''
AND
CONTAINS((myField1, myField2),@SearchText)


我可以像这个,但我想避免重复的代码:

  DECLARE @SearchText VARCHAR(1000); 
SET @SearchText =''

IF @SearchText =''
BEGIN
SELECT * FROM myTable
WHERE
/ *
某些会话
* /
END
ELSE
BEGIN
SELECT * FROM myTable
WHERE
/ *
某些转换
AND
* /

@SearchText =''


@SearchText<>''
AND
CONTAINS((myField1,myField2),@SearchText)


END



我找到了答案这里



所以解决方法是将@SearchText设置为'',而不是将其留空。

解决方案

我找到了答案这里

所以解决方案是设置@SearchText为'',而不是将它留空。


Is there a way to avoid the error Null or empty full-text predicate in the example below ?

DECLARE @SearchText VARCHAR(1000);
SET @SearchText = ''

SELECT * FROM   myTable
WHERE
    /* 
    SOME CONTITIONS 
    AND
    */ 
    ( 
      @SearchText = ''
      OR
      (
        @SearchText <> ''
        AND
        CONTAINS((myField1, myField2), @SearchText)
      )
    )

I could be doing like this, but I want to avoid duplicating the code :

DECLARE @SearchText VARCHAR(1000);
SET @SearchText = ''

IF @SearchText = ''
BEGIN
  SELECT * FROM   myTable
  WHERE 
      /* 
      SOME CONTITIONS 
      */ 
END
ELSE
BEGIN
  SELECT * FROM   myTable
  WHERE
      /* 
      SOME CONTITIONS 
      AND
      */ 
      ( 
        @SearchText = ''
        OR
        (
          @SearchText <> ''
          AND
          CONTAINS((myField1, myField2), @SearchText)
        )
      )
END

[EDIT]

I found the answer here

So the solution is to set the @SearchText to '""' instead of leaving it empty.

解决方案

I found the answer here

So the solution is to set the @SearchText to '""' instead of leaving it empty.

这篇关于是否全文搜索CONTAINS子句总是被评估?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆