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

  • SEARCH
  • Home
  • 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 9103859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:43:48+00:00 2026-06-17T01:43:48+00:00

I have a Table Valued Parameter (@KEYWORD) which just has one column with 0

  • 0

I have a Table Valued Parameter (@KEYWORD) which just has one column with 0 to many rows of keywords that will query against one or two database (nvarchar) columns (REMARKS and SUPPLEMENTAL_REMARKS). Super simple concept.

What I am having trouble with is how to write the SQL to have it check for each of the individual keywords supplied against that one (or two) database columns.

Here’s my unfinished part of the WHERE clause…

WHERE
(
    CASE WHEN EXISTS (SELECT 1 FROM @KEYWORD) THEN
        --check that some combination of either REMARKS or SUPPLEMENTAL_REMARKS contains all supplied values
        CASE WHEN (
        --  RES.REMARKS (or RES.SUPPLEMENTAL_REMARKS) LIKE %keyword[0]%
        --  AND
        --  RES.REMARKS (or RES.SUPPLEMENTAL_REMARKS) LIKE %keyword[1]%
        --  AND
        --  ... (this doesn't work for many reasons, but is just to give an idea)
        ) THEN
            1
        ELSE
            0
        END
    ELSE --TVP (@KEYWORD) not supplied, so ignore this filter
        1
    END
) = 1
  • 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-17T01:43:50+00:00Added an answer on June 17, 2026 at 1:43 am

    Base on the SQL comment below you only want records from res where all the keyword match on either REMARKS or SUPPLEMENTAL_REMARKS.

     --  REMARKS (or SUPPLEMENTAL_REMARKS) LIKE %keyword[0]%
            --  AND
            --  REMARKS (or SUPPLEMENTAL_REMARKS) LIKE %keyword[1]%
            --  AND
            --  ... (this doesn't work for many reasons, but is just to give an idea)
    

    The easiest way to do that is JOIN and do a count and make sure it matches the number of keywords in @KEYWORD

    DECLARE @KEYWORDCOUNT as INT
    SELECT @KEYWORDCOUNT = COUNT(*) FROM @Keyword
    
    SELECT ID, [REMARKS], [SUPPLEMENTAL_REMARKS]
    FROM 
      res r
      INNER JOIN @Keyword k
      ON r.REMARKS like '%' + k.keyword + '%'
         OR r.SUPPLEMENTAL_REMARKS like '%' + k.keyword + '%'
    
    
    GROUP BY 
      ID,[REMARKS], [SUPPLEMENTAL_REMARKS]
    HAVING COUNT(ID) = @KEYWORDCOUNT
    

    One way for it into your where is like so

    WHERE
      @KEYWORDCOUNT = 0 
      OR 
      res.id in (SELECT ID
                FROM 
                    res r
                    INNER JOIN @Keyword k
                   ON r.REMARKS like '%' + k.keyword + '%'
                     OR r.SUPPLEMENTAL_REMARKS like '%' + k.keyword + '%'
                 GROUP BY 
                  ID
                 HAVING COUNT(ID) = @KEYWORDCOUNT)
    

    You might want to consider passing @KEYWORDCOUNT in as a parameter since DataTable.Rows.Count almost free

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of many values where one column has the WO Number,
Currently, I have a table that has a column which has a datatype enum.
I have a stored procedure that uses a table valued function which executes in
I have a procedure that receives a table as a parameter. I need to
I have been investigating Table-Valued Parameters in SQL Server 2008, and I've discovered that
I have a table named Workflow. It has 37M rows in it. There is
I have a stored proc that I am passing two parameters into. One parameter
I have a stored procedure in my database that takes a table value parameter,
I have an interesting problem. I will write a scalar-valued function. One of the
So I have this user-defined table type parameter, which is used in my scalar

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.