sql server - How to use CASE in WHERE clause for short circuiting CONTAINS -


i have stored procedure searching takes several optional parameters. 1 of @keywords defined as

@keywords nvarchar(1000) = null, 

if @keywords null or empty string, want short circuit, otherwise need search full text index. logic used this:

where (@keywords null or contains( (title, crossref, company_name), @keywords)) , -- other search terms 

however, discovered or not guaranteed short circuit, returns error "empty full-text predicate." apparently case supposed guaranteed short circuit, versions of sql server have bug isn't case.

here's i'm trying:

where  (1 = case     when @keywords null 1     when @keywords = '""' 1     else (case when contains( (title, crossref, company_name), @keywords) 1 else 0 end) ) , -- other search terms 

this still gives "empty full-text predicate" error. i'd happy replace @keywords match, i'm not sure how either.

since you're using sp, why not throw if else blocks implement short-circuit logic. not easier read, optimizer better well.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -