Showing posts with label replacement. Show all posts
Showing posts with label replacement. Show all posts

Sunday, March 11, 2012

Double quotes replacement

Hi,

It seems to be simple, however, it stumbles me.
how to replace all the double quotes (") within the following
sentence (or a column) with single quotes ('),

colA = this is a freaking "silly" thing to do
into
colA this is a freaking 'silly' thing to do

Select Replace(colA,'"',''')
>From tblXYZ

won't work,

Select Replace(colA,'"',"'")
>From tblXYZ

won't work neither.

How come? Thanks.You need to specify 2 single quotes within the literal string when 1 quote
is desired. Try:

Select Replace(colA,'"','''')
From tblXYZ

--
Hope this helps.

Dan Guzman
SQL Server MVP

"NickName" <dadada@.rock.com> wrote in message
news:1125889758.581518.99700@.g49g2000cwa.googlegro ups.com...
> Hi,
> It seems to be simple, however, it stumbles me.
> how to replace all the double quotes (") within the following
> sentence (or a column) with single quotes ('),
> colA = this is a freaking "silly" thing to do
> into
> colA this is a freaking 'silly' thing to do
> Select Replace(colA,'"',''')
>>From tblXYZ
> won't work,
> Select Replace(colA,'"',"'")
>>From tblXYZ
> won't work neither.
> How come? Thanks.|||Thank you very much, Dan, works perfect.

On a related note, BOL does not cover it, how could one find a solution
to a problem similar to this one without resorting to this NG?|||I found this from the 'quotation marks' entry in the Books Online index.
From the 'Using char and varchar data' topic:

<Excerpt href="http://links.10026.com/?link=acdata.chm::/ac_8_con_03_7mch.htm">
When using single quotation marks to delimit a character constant that
contains an embedded single quotation mark, use two single quotation marks
to represent the embedded single quotation mark, for example:

SET @.MyCharVar = 'O''Leary'
</Excerpt
--
Hope this helps.

Dan Guzman
SQL Server MVP

"NickName" <dadada@.rock.com> wrote in message
news:1125967013.923190.247670@.g14g2000cwa.googlegr oups.com...
> Thank you very much, Dan, works perfect.
> On a related note, BOL does not cover it, how could one find a solution
> to a problem similar to this one without resorting to this NG?|||Man, I can't read, ok, not careful, thanks.