SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 [Solv]Like statement runs without any value given?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vrutin
Starting Member

United Kingdom
3 Posts

Posted - 03/21/2013 :  19:26:46  Show Profile  Reply with Quote
This statement runs as if I am calling all the rows of the column Appname.

SELECT Appname FROM Application
WHERE appname like '%';

Any reasons why this is happening? Shouldnt it throw error if nothing is passed @ '%'

Thanks in advance
Vrutin

Edited by - Vrutin on 03/21/2013 22:01:42

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 03/21/2013 :  19:55:55  Show Profile  Reply with Quote
"%" is a wildcard, so everything is like '%'. If you want to find where "%" is an actual symbol in appname, try
SELECT Appname FROM Application
WHERE appname like '[%]';

Jim



Everyday I learn something that somebody else already knew
Go to Top of Page

Vrutin
Starting Member

United Kingdom
3 Posts

Posted - 03/21/2013 :  20:08:58  Show Profile  Reply with Quote
^ Hey,
Basically I have attached the above query to a ASP:Textbox and I am taking the user input and concatenating it with rest of the query in the following way:

like '[USER INPUT]%';

However, when the user types nothing into the searchbox USER INPUT is nothing. So, I want to ignore the blank and only run the query if they typed any character.
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 03/21/2013 :  21:21:05  Show Profile  Reply with Quote
Then wouldn't that best be handled in ASP? I know zilch about ASP, but can't you check to see that ASP:Textbox <> ''?
Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Vrutin
Starting Member

United Kingdom
3 Posts

Posted - 03/21/2013 :  22:01:01  Show Profile  Reply with Quote
^ Hey, I just did what you said and tada Sucess!

I dont know why I was behind sql ignoring the blank. It was done easily using C#.

Anywais, Thanks for orienting my mind to think out of the box.

Regards
Vrutin
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000