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 3973918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:30:25+00:00 2026-05-20T04:30:25+00:00

I have a Stored Proc which performs search on records. The problem is that

  • 0

I have a Stored Proc which performs search on records.

The problem is that some of the search criteria,which are coming from UI, may be empty string.
So, when the criteria not specified, the LIKE statement becomes redundant.

How can I effectively perform that search or Sql Server? Or, Does it optimize LIKE(‘%%’) query since it means there is nothing to compare?

The Stored proc is like this:

ALTER PROC [FRA].[MCC_SEARCH]
@MCC_Code varchar(4),
@MCC_Desc nvarchar(50),
@Detail nvarchar(50)
AS
BEGIN             
       SELECT
             MCC_Code,
             MCC_Desc,
             CreateDate,
             CreatingUser

       FROM
              FRA.MCC (NOLOCK)
       WHERE
             MCC_Code LIKE ('%' + @MCC_Code + '%')
             AND MCC_Desc LIKE ('%' + @MCC_Desc + '%')
             AND Detail LIKE ('%' + @Detail + '%')
       ORDER BY MCC_Code

END
  • 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-05-20T04:30:26+00:00Added an answer on May 20, 2026 at 4:30 am

    The short answer is – no
    The long answer is – absolutely not

    Does it optimize LIKE(‘%%’) query since it means there is nothing to compare?

    The statement is untrue, because there is something to compare. The following are equivalent

    WHERE column LIKE '%%'
    WHERE column IS NOT NULL
    

    IS NOT NULL requires a table scan, unless there are very few non-null values in the column and it is well indexed.

    EDIT

    Resource on Dynamic Search procedures in SQL Server:
    You simply must read this article by Erland Sommarskog, SQL Server MVP http://www.sommarskog.se/dyn-search.html (pick your version, or read both)

    Otherwise if you need good performance on CONTAINS style searches, consider using SQL Server Fulltext engine.

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

Sidebar

Related Questions

I have a stored proc which inserts rows from a view with ranks into
I have a stored proc that performs a fairly complex SELECT statement. The stored
I have a Stored Proc query below which involves returning partial delimited search string.
I have a Stored proc which returns 6 select statement results. I'm trying to
I am using SQL 2000. I have a stored proc, spGetApplicantList , which cannot
I have a VB.Net function which executes a Oracle Stored Proc and returns a
I have a stored proc that processes a large amount of data (about 5m
I have a Stored Proc that do a validation on a parameter ex. IF
I have a stored proc on an existing 3rd party application (SQL 2005) that
I have a stored proc on sql server 2008 that excepts a int parameter.

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.