how to use a string that contain ' in SQL "IN" clause

i have a string value like 'Apple's'. i want to use this string in SQL "IN" clause like below query

select * from tbl_fruit where nm_fruit IN(''Apple's'','Orange'); 

how i can get the above query work correctly ?

Many Thanks, Awais Afzal.

2 Answers

double the single quotes,

select * from tbl_fruit where nm_fruit IN ('Apple''s', 'Orange') 

but if you do it on the application level, make sure you parameterized the query :)

1

I have found SQL correctly interprets the ASCII single-closed-quote (ALT 0146) as an apostrophe in searches while the "IN" treats it like any other character. Now I can search for 'Matt's Macintosh' using Matt(ASCII character 0146)s Macintosh" without messing up my list or the search.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like