I am having an address like
"1500 bustleton pike churchville,
Southampton, PA 18966, United States"
and its also present in my database. But when i used in query like
select id from companies where CompanyAddress
LIKE '1500 bustleton pike churchville,
Southampton, PA 18966, United States'
it not returning any value. Because its contain a new line after "churchville,"
. Please help me to solve this
There are two potential problems:
Most likely issue is that it's a (LF) and/or (CRLF) check.
Second is that there are or are not spaces around the line break
If you're really not sure, check out the REPLACE() function: find out if your search is or and then match in the following:
select id from companies
WHERE REPLACE(CompanyAddress, '
', '
') =
'1500 bustleton pike churchville,
Southampton, PA 18966, United States'
where the second parameter in the REPLACE
is the one you have in source code. Check the spaces in query match (or also remove spaces with REPLACE
).
I would suggest ensuring the string is entered in a standard form for future searching to get around this problem.
NOTE: don't do this on a large file as the search won't be indexed.
THERE ARE MANY WAYS TO DO IT..!!
Use MYSQL TRIM()
:
select id from companies where trim(BOTH '
' from CompanyAddress)
LIKE '%1500 bustleton pike churchville, Southampton, PA 18966, United States%'
If you works with MySql 5.1, use REPLACE()
:
select id from companies where REPLACE(CompanyAddress,'
',' ')
LIKE '%1500 bustleton pike churchville, Southampton, PA 18966, United States%'