Is Full Text Search CONTAINS clause always evaluated?

谁说我不能喝 提交于 2019-12-10 23:37:57

问题


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.


回答1:


I found the answer here.

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



来源:https://stackoverflow.com/questions/9216608/is-full-text-search-contains-clause-always-evaluated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!