Link to home
Start Free TrialLog in
Avatar of 1Cougar
1Cougar

asked on

Getting text from table with single and double quotes

Hello,

I would like to create a function that will be passed in quite a lot of text and which will replace any single and/or double quotes with the html value for them.  I have tried the code below but I get an error in compiling it....

I am not sure what I am doing wrong.  Any help would be much appreciated.

Cheers,

DECLARE @X nvarchar(100)
DECLARE @MyText nvarchar(100)
SET @MyText = 'he's not "very" good'

SET @X = REPLACE(@MyText,'"','"')
SET @X = REPLACE(@X,'''''',''')

PRINT @X

Open in new window

Avatar of John_Vidmar
John_Vidmar
Flag of Canada image

In a single-quote delimited value (Line 3), you need 2 single-quotes to represent a single-quote:
SET @MyText = 'he''s not "very" good'

Open in new window

Avatar of 1Cougar
1Cougar

ASKER

Hello and thank you....but the text in the database (entered by a user) has only single quote.  I want to retrieve this text but I need to change the single quote to '''

?

Thanks again,
ASKER CERTIFIED SOLUTION
Avatar of Surendra Nath
Surendra Nath
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
replace(replace(mytext,char(34),'"'),char(39),'&#39')