Jump to content

= vs like


caradri

Recommended Posts

Hi, all. 

I have a strange issue, i think.

i have a sql database and a simple select query "select * from tablename where columname='stringtosearch'; "

this work fine until today, today only works with like:

"select * from tablename where columname LIKE '%stringtosearch%'; "

WHY???😭

Link to comment
Share on other sites

The semi-colon will not break the query, it will simply be ignored.

The = operator will only return a row if the entire field exactly matches what is being searched. If you want to find rows that contain the search string along with more content then you must use the LIKE operator. If you think the fields do match exactly, make sure that they don't actually have spaces, tabs or other invisible characters that might be interfering with the search.

Link to comment
Share on other sites

21 minutes ago, Ingolme said:

The semi-colon will not break the query, it will simply be ignored.

The = operator will only return a row if the entire field exactly matches what is being searched. If you want to find rows that contain the search string along with more content then you must use the LIKE operator. If you think the fields do match exactly, make sure that they don't actually have spaces, tabs or other invisible characters that might be interfering with the search.

27 minutes ago, dsonesuk said:

If that is exactly what you use, then maybe you should try it without the semicolon within the SQL query

hi. this was working until now. and the string is exactly like in database. the data type is nchar(30), and looks like in the database its fill the string with white spaces to get length 30.

may the datatype do that problem? something can make a change?

Link to comment
Share on other sites

If the string is not exactly 30 characters long, use VARCHAR instead of CHAR. CHAR adds additional null bytes as padding if the string is not long enough for the field.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...