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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:11:44+00:00 2026-06-13T19:11:44+00:00

I am trying to set a like parameter into a variable and allow that

  • 0

I am trying to set a like parameter into a variable and allow that variable to accept wild cards (mssql 2005). If I use my parameter set to ‘%’ it only returns a partial subset but if I hard code the query to use ‘%’ it returns the full set. Why might the variable behave differently to the string?

DECLARE @wareno char(4); 
SET @wareno = '%';
select @wareno as a, * from waredesc where wareno like @wareno;

vs

DECLARE @wareno char(4); 
SET @wareno = '%';
select @wareno as a, * from waredesc where wareno like '%';

The full scenario is switching based on a flag but is reproducible under the code above

DECLARE @wareno char(4); 
DECLARE @delprods bit;

/**
SET THESE PARAMETERS
**/
SET @wareno = '1'; 
SET @delprods = 'true'; /** if true all the warehouses should also be emptied for safety - products are held at a company level!**/

IF @delprods = 1
BEGIN
    SET @wareno = '%';
END
select @wareno as a, * from waredesc where wareno like @wareno;

Thanks

  • 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-13T19:11:46+00:00Added an answer on June 13, 2026 at 7:11 pm

    The char(4) variable will be padded out with three trailing spaces.

    These are significant in a LIKE pattern and it will only match values ending in three spaces. Use varchar(4) instead.

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

Sidebar

Related Questions

I am trying to set an application icon (python3 / tkinter) like this: Interface()
I'm trying to set the HttpRequestHeader for a HttpWebRequest like so: new HttpWebRequest().Headers.Add(HttpRequestHeader.UserAgent, Mozilla/4.0);
I'm trying to set a function to do something like this def __binaryTreeInsert(self, toInsert,
I'm trying to set java.awt.headless=true during the application startup but it appears like I'm
I trying to set separate style for particular widgets, like for one button with
I am trying to set [Ctrl]-[;] as a keybinding in my .emacs like this
Trying to learn about php's arrays today. I have a set of arrays like
Is it possible to set for(AssociatedControlID) attribute using jQuery? I am trying something like
I'm trying to build more generic query functionality into my application. What I'd like
I have a stored proc that I am passing two parameters into. One 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.