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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:54:42+00:00 2026-05-16T04:54:42+00:00

I have a select statement that is used in a gridview via a stored

  • 0

I have a select statement that is used in a gridview via a stored procedure:

SELECT * FROM T_Computer WHERE (ISTag LIKE '%' + @ISTag + '%') AND Status <> 'Trashed' AND Status <> 'Sold' AND Status <> 'Stored'

The @ISTag, an nchar is determined by a textbox value, if the textbox is empty I have the default value set to %, which in my mind should essentially negate that part of the where clause and return all of the rows except the ones negated by the Status column. Instead it isn’t returning anything. If I remove the “+ @ISTag +” it does what I want.

Basically three %’s return nothing, but 2 %’s return what I want. How should I fix this?

  • 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-16T04:54:43+00:00Added an answer on May 16, 2026 at 4:54 am

    I’m really intrigued by this. For a start, I ran these two queries against a table with 13221 rows, and got every single row in the first instance, and about half of them in the second:

    declare @rad char(30)
    select @rad = '%'
    
    select count(*) from xofdoc where docdesc like '%%%'
    select count(*) from xofdoc where docdesc like '%' + @rad + '%'
    

    ON THE OTHER HAND, if I change the declaration of @rad to varchar(30), both queries pull all the rows.

    The reason I bring this up is because there may be something going on with the data declaration of your @IsTag. You didn’t say how it was declared. This is important because a char is a fixed-length string, meaning that a char(5) for example, set to the value of '%' will actually have the value '% '. So, the statement '%' + '% ' + '%' evaluates to: '%% %'. So it would only find rows which had at least four consecutive spaces in the whered column. On the other hand, a varchar is a variable length item, and trailing spaces are ignored, which results in '%%%' in the above case, and thus wildcards the entire column.

    Edited to add: nchar or char, it makes no difference in this case. If you’re using nchar now, change it to nvarchar.

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

Sidebar

Related Questions

I have a SQL statement that looks like: SELECT [Phone] FROM [Table] WHERE (
i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses
If i have a parameterized SQL statement like this: SELECT * FROM table WHERE
I have a LEFT JOIN select statement that retrieves values from 2 tables: tableA
Suppose I have a SELECT statement that returns some set of results. Is there
I have a relatively simple select statement in a VB6 program that I have
I have a select statement with calculated columns and I would like to use
I have the following statement SELECT id, descr from mytable which returns 1, 'Test1'
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
I have views which look something like this: mysql> select * from p2; +---+---------+---------+

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.