I have this Stored Procedure which returns records containing the specified keyword.
CREATE procedure [dbo].[SearchKeywordPaged](
@KeyWordFilter varchar(50)
,@PageNumber int = 1)
as
begin
declare @PageSize int = 50
declare @FirstRow int
declare @LastRow int
declare @TotalRows int
SELECT @FirstRow = (@PageNumber - 1) * @PageSize + 1,
@LastRow = (@PageNumber - 1) * @PageSize + @PageSize;
select @TotalRows = COUNT(*) from
[Quotes] q inner join [Keywords] k
ON q.id = k.Quoteid where k.Keyword = @KeyWordFilter;
with Results as
(
SELECT
q.*
,ROW_NUMBER() over (Order By Author asc) as Instance_Count
,@TotalRows as the_Count
FROM [Quotes] q
INNER JOIN [Keywords] k ON q.id = k.Quoteid
WHERE k.Keyword = @KeyWordFilter
)
select *
from results
where Instance_Count between @FirstRow and @LastRow
order by Instance_Count asc
end
How can I modify this stored procedure to accept more than 1 keyword for search ?
Create a function that convertes a string into a table. You can use the example below:
Then, modify the
WHEREclause of your stored procedure like this:Finally, you can use your SP passing a list of keywords as a comma separated list, like this: