I have been struggling for quite some time to get this query going.
In short my query searches by fileno and/or searchfield
DECLARE @pSearchFor AS NVARCHAR(100);
— I am here testing with null value, ‘ ‘ , or seperate words
SET @pSearchFor = null — ‘”marsa” and “mosta”‘;
IF ISNULL(@pSearchFor,'') = '' SET @pSearchFor = '""' ;
declare @fileNo nvarchar(50) = 'e/e'
select top 1000 r.FileId, r.FileNo, fs.SearchField, @pSearchFor
from regfile as r
left outer join FileSearchFields as fs on r.FileId = fs.FileID
where r.FileNo like
CASE
WHEN Len(@fileno) > 1 THEN '%'+@fileNo+'%'
ELSE r.FileNo
END
AND
1 =
CASE WHEN ISNULL(@pSearchFor, '') = '' THEN 1 ELSE 0 END
or CONTAINS(fs.SearchField, @pSearchFor)
I am getting nothing returned if @pSearchFor is null otherwise works great.
I need to return all instances if a null
One possible solution might be to call 2 seperate sps or use if /else but probably exists a better method.
I really do appreciate your help!
I have solved the problem. Maybe this may be of some help to others!
This is a snippet of my stored procedure.