Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:22:17+00:00 2026-06-17T22:22:17+00:00

I have this Stored Procedure which returns records containing the specified keyword. CREATE procedure

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:22:18+00:00Added an answer on June 17, 2026 at 10:22 pm

    Create a function that convertes a string into a table. You can use the example below:

    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_SplitString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
    DROP FUNCTION [dbo].[fn_SplitString]
    GO
    CREATE   FUNCTION [dbo].[fn_SplitString]    (@xStr varchar(8000))
    RETURNS @out table (
        x varchar(500))  AS  
    begin
    
    declare @lp int set @lp=1
    declare @xlen int
    set @xlen=len(@xstr)
    
    declare @xchar char(1)
    declare @thisSplit varchar(50)
    set @thisSplit=''
    
    while @lp <= @xlen
     begin
        set @xchar=substring(@xstr,@lp,1)
    
        set @thisSplit=@thisSplit + @xchar
    
            if (@xchar=',') or (@lp=@xlen)
             begin
                insert into @out (x) values (replace(@thisSplit,',',''))
                set @thisSplit=''
             end
        set @lp=@lp+1   
     end
    
    
    RETURN  
    end
    GO
    select X from fn_SplitString('aaa,bbb,cccc')
    

    Then, modify the WHERE clause of your stored procedure like this:

    WHERE k.Keyword in (select x from fn_SplitString(@KeyWordFilter) ) 
    

    Finally, you can use your SP passing a list of keywords as a comma separated list, like this:

    exec [SearchKeywordPaged]  @KeyWordFilter='keyword1,keyword2,...'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question, I have a Stored Procedure which returns a value. This
I am facing this problem. I have a stored procedure which returns 6 rows
I have this stored procedure, which is mapped in an Entity Framework 4.1 object.
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,
I have this stored procedure for Oracle: create or replace procedure bns_saa_message_get() <--- PROBLEM
I have this stored procedure which I am using to populate a user table.
Using a stored procedure i have a fairly complex SQL statement which returns a
I have a stored procedure, which returns a cursor. The application passes a parameter
I have a stored procedure in Oracle 9i which inserts records in a table.
I have a stored procedure which returns a value (ex: GetData ) How can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.