Neo
Neo

Reputation: 541

pulling data value that has apostrophe but your input does not?

I have a table with a column name title however the data has apostrophe in it.
My query input parameter removes all apostrophe from it, how would you compare like or equal to get that row back?

select * from authors..atricles where title = 'buyers'
buyer's = 'buyers' or like '%buyers%'

If a user inputs buyer's on the page it will remove ' and the new input string will be buyers.

Upvotes: 0

Views: 387

Answers (2)

Snake_Plissken
Snake_Plissken

Reputation: 400

I think this should work:

SELECT * FROM authors WHERE title LIKE'%buyer%'

Upvotes: 0

Kermit
Kermit

Reputation: 34063

To escape it, you add another single quote:

WHERE title LIKE '%buyer''s%'

Since you mention your query input parameter removes all apostrophes, then you would search using REPLACE:

WHERE REPLACE(title, '''', '') = 'buyers'

Using functions in this fashion will make any possible indexes useless.

Upvotes: 2

Related Questions