Solved

Getting text from table with single and double quotes

Posted on 2014-01-22
4
206 Views
Last Modified: 2014-03-12
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

0
Comment
Question by:1Cougar
4 Comments
 
LVL 11

Expert Comment

by:John_Vidmar
ID: 39799798
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

0
 

Author Comment

by:1Cougar
ID: 39799843
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,
0
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39799977
I just corrected your code check the new one below

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

0
 
LVL 32

Expert Comment

by:awking00
ID: 39800885
replace(replace(mytext,char(34),'"'),char(39),'&#39')
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question