caradri Posted June 24, 2018 Share Posted June 24, 2018 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 More sharing options...
dsonesuk Posted June 24, 2018 Share Posted June 24, 2018 If that is exactly what you use, then maybe you should try it without the semicolon within the SQL query Link to comment Share on other sites More sharing options...
Ingolme Posted June 24, 2018 Share Posted June 24, 2018 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 More sharing options...
caradri Posted June 24, 2018 Author Share Posted June 24, 2018 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 More sharing options...
Ingolme Posted June 25, 2018 Share Posted June 25, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now