Simple question - searching for text that contains an apostrophe

  • We were recently upgraded to a SQL 2008. In the past, if I wanted to search for text that inadvertently contained something SQL would recognize as a command, I would contain it in quotations: For example select * from table where column 1 = '"Dad's"'

    and that would return it. Now if I do that, it recognizes the apostrophe as the end of the field. Is there an easy way to deal with this?

    Thanks,

    Teena

  • something like this works...the important part is that two single quotes in a row is the escape sequence, so it can be contained within single quotes:

    select * from yourtable where yourfield like '%''%' --contains at least one apostrophe

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you. I have text that needs to be updated to include an apostrophe as it will print on a document. So, if I want to update the text to include an apostrophe, how would I do that?

    For instance

    Update table1

    set title = 'Daddy's Daycare'

  • teh same escape method: two single quotes in a row:

    For instance

    Update table1

    set title = 'Daddy''s Daycare'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you very much!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply