Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 [Solv]Like statement runs without any value given?

Author  Topic 

Vrutin
Starting Member

3 Posts

Posted - 2013-03-21 : 19:26:46
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

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2013-03-21 : 19:55:55
"%" 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

3 Posts

Posted - 2013-03-21 : 20:08:58
^ 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
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2013-03-21 : 21:21:05
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

3 Posts

Posted - 2013-03-21 : 22:01:01
^ 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
   

- Advertisement -