Problem is, if i send in %word% OR body LIKE %word2% i get no results but if i just send in %word% then i get results (i know there are results since i ran a regular query (not SP one) and got the results.
You cannot pass in (as a parameter) programming syntax language. [ OR body LIKE ]. You need to pass in two separate parameters and have the [OR body LIKE ] previously established as part of the @sql.
That is correct.
Have the [ OR LIKE ] in your code, and pass in both search strings as parameters. You could optionally build the @sql string to include [ OR LIKE ] IF the second parameter is not null.
You have to chnage the following statements..
Forser wrote:
SELECT @sql = 'SELECT @sTitle = f.title, @sName = f.name, @sPath = f.path, @sBody = c.designBody, @sDate = c.lastModify
FROM files AS f INNER JOIN contents AS c ON c.fileId = f.id WHERE (f.status = 2) AND (c.designBody LIKE @sWord)
ORDER BY c.lastmodify DESC';
SET @ParmDefinition = N'@sWord nvarchar(4000), @sTitle nvarchar(500) OUTPUT,
@sName nvarchar(500) OUTPUT, @sPath nvarchar(500) OUTPUT,
@sBody nvarchar(4000) OUTPUT, @sDate DateTime OUTPUT';
EXEC sp_executesql @sql, @ParmDefinition, @sWord = @searchWord, @sTitle = @searchTitle OUTPUT, @sName = @searchName OUTPUT, @sPath = @searchPath OUTPUT, @sBody = @searchBody OUTPUT, @sDate = @searchDate OUTPUT;
SELECT @sql = 'SELECT @sTitle = f.title, @sName = f.name, @sPath = f.path, @sBody = c.designBody, @sDate = c.lastModify
FROM files AS f INNER JOIN contents AS c ON c.fileId = f.id WHERE (f.status = 2) AND ' + Isnull(@sWord,' 1=1') + '
ORDER BY c.lastmodify DESC';
SET @ParmDefinition = N'@sWord nvarchar(4000), @sTitle nvarchar(500) OUTPUT,
@sName nvarchar(500) OUTPUT, @sPath nvarchar(500) OUTPUT,
@sBody nvarchar(4000) OUTPUT, @sDate DateTime OUTPUT';
EXEC sp_executesql @sql, @ParmDefinition, @sTitle = @searchTitle OUTPUT, @sName = @searchName OUTPUT, @sPath = @searchPath OUTPUT, @sBody = @searchBody OUTPUT, @sDate = @searchDate OUTPUT;
Yes.
You have to pass your argument something like this..
'c.designBody LIKE ''%word2%'' part'