Showing posts with label apostrophes. Show all posts
Showing posts with label apostrophes. Show all posts

Wednesday, March 21, 2012

Replace function: replacing an apostrophe with whatever

hey

i'm having a problem with a stored procedure, to cut a long story short i need to replace apostrophe's in my text, like so

SET @.prOtherValue = REPLACE(@.prOtherValue,''', '''')

this doesn't work tho

whats the work around

cheers!!!!

SET @.prOtherValue = REPLACE(@.prOtherValue,''', '')

|||

nar.. no good

this is the context i have it in

SET @.prOtherValue = REPLACE(@.prOtherValue,''','')

EXEC( 'UPDATE #_AllParticipantResponses SET '+@.qcTitle+' = '''+@.prOtherValue+''' WHERE participantId='+@.globalparticipantId+'')

the problem is in @.prOtherValue, sometimes i'll have the word isn't or whatever word, which contains an apostrophe

if you copy and paste the above into query analyzer, watch what hapens to the EXEC statement if you have an apostrophe where i have bolded

|||

SET @.prOtherValue=REPLACE(@.prOtherValue,'''','')

EXEC('UPDATE #_AllParticipantResponses SET '+ @.qcTitle+' = '''+ @.prOtherValue+''' WHERE participantId= '+convert(Varchar,@.globalparticipantId))

|||

hehe...

nar, you have 2 appostrophes for the second argument

in my database right, i have a column called OtherValue. in this column, i have words like isn't can't it's ( focus on the single appostrophe in each word)

when i try and pass words like isn't to my @.prOtherValue, the update statement fails because the @.prOtherValue value contains an appostrophe ( ' )

apostrophe's on t-sql have some sort of formatting value

when i try to execute the update statement, if i have an appostrophe in a word, it terminates

what i need to do isREPLACE(@.prOtherValue,''','whatever') but you can't have'''

cheers!!!

|||

Replace(prOtherValue,char(39),'|')

|||

Finally got a chance to try it out

Thanks for that

Replace Apostrophes for Openquery?

Hi All,

I have trigger that sends data from one table to another.
I am using the Openquery statement within the trigger to send the data.

However when I Insert anything with an apostrophe into the table where the trigger resides it errors saying...

"Incorrect syntax near" where the apostrophe is and this puts out the number of Quotes in the Openquery Statement.

I use the Replace function written as REPLACE(@.VARIABLE, '''', ''') to replace One Apostrophe with 2.
I'm not sure whether I can use this with Openquery or not / or whether the syntax is correct for Replace in conjunction with OpenQuery.

If someone can give me anysight into this and any code on how to do this would be great.

Thanks
AnthonyYou are posting on multiple forums :)

Once again EXEC(), QUOTENAME()|||How do I use QUOTENAME() if I want to use a variable that has a value of "O'Reilly" for instance for the following OPENQUERY statement within the trigger

SET @.TSQL = 'INSERT INTO ' +
'OPENQUERY(AUTHTEST,''Select nar_num, ser_key, alp_key from aunrmast'') ' +
'VALUES(0, '''', ''' + @.VARIABLE + ''', 99)'

EXEC(@.TSQL)

Thanks for your help on this

Anthony|||select QUOTENAME('O''Reilly','''')sql