Jump to content

Search for Data containing quote mark


chemfree

Recommended Posts

A filed in my data has some words that are imported with quote marks on either side of the word. I need to be able to search the records to find the rows containing them as well as those which don't.

 

The data may look someting like: Alfred "T" or Alfred T.

 

When I use 'like  %string%' in the WHERE clause of the SQL and use 'Alfred "T" as the search input, I get no results. However, if I use '"' as the search input, Alfred "T" will be found. If, I use 'Alf' as the string input, MySQL finds 'Alfred T', but not 'Alfred "T"'.

 

I do not want to strip the quote from the data as they are unique names that may include the quote"

 

What should my SQL look like to find names with or wihout the quote in the field?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/116877-search-for-data-containing-quote-mark/
Share on other sites

try something like

SELECT
IF(T1.Fieldname LIKE '%STRING%', '1', '0') as Match,
T1.PRIMARYKEY as RowID
FROM `TABLENAME` as T1

 

That should get you all rows and then if it matches the "string" return a 1 or else a 0 to tell you matching/non matching rows.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.