SQL query problem

  • i have a value in DB abc'def

    How do i query for this value ? i am afraid that there is a special char inside.

    Select * from MyTable

    where col1 ='abc'def'

    This wont work

    how do i do it ?

  • Hi try where col1 = 'abc''def'

    Two single quotes, the first quote 'escapes' the the second quote effectively saying the quote is part of the string and not the termination of the string.

  • if your parameter is not fixed i.e. if value which you are comparing may contain Single Quotation mark or may not.. in that case before comparing first check for Single Quotation mark and replace it will two single quotation mark

    If you are using VB front end you can use replace command

    syntax: Replace(string,"'","''")

    you can find similar command in other front ends

  • Try this:

    where col1 like 'abc'def'

    or

    where col1 like '%abc'def%'

    Jagan

  • That will just give you syntax errors - double up the single quote.

  • WHERE @col1 LIKE 'abc_def'

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Please, take a look at the examples at

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_la-lz_115x.asp

    LIKE article in Transact-SQL Reference

    Better read all article, but if you don't have time then scroll to the middle of the article to the topic:

    Pattern Matching with the ESCAPE Clause

    Regards,Yelena Varsha

  • Where col1 like '%''%'

     

    If its a name that'll get your O'Doyles and O'Connors

Viewing 8 posts - 1 through 7 (of 7 total)

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