replace single quotes sql server

we are trying this

UPDATE table1
SET description = REPLACE([description], '''', '') where username ='user123'

error:

Argument data type text is invalid for argument 1 of replace function.
goodluck11Asked:
Who is Participating?
 
Patrick MatthewsConnect With a Mentor Commented:
Convert the text before doing the replace:

UPDATE table1
SET description = REPLACE(CONVERT(varchar(max), [description]), '''', '') 
where username ='user123'

Open in new window

0
 
goodluck11Author Commented:
this is on SQl server 2008
0
 
dqmqCommented:
This might work:

UPDATE table1
SET description = cast(REPLACE(cast([description] as varchar(max)), '''', '') as text) where username ='user123'
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dqmqCommented:
or the better long term solution: permanently convert the column to varchar(max)
0
 
NorieConnect With a Mentor VBA ExpertCommented:
I think it could be a problem with the quotes, which is why you posted the question I suppose.

Anyway, try using CHAR(39) where 39 is the ASCII code for a single quote.

UPDATE table1
SET description = REPLACE([description], CHAR(39), '') where username ='user123'
0
 
Patrick MatthewsCommented:
dqmq wrote:

or the better long term solution: permanently convert the column to varchar(max)

Agreed!

imnorie wrote:

I think it could be a problem with the quotes

Unlikely.  The error message is consistent with passing a text or ntext value into the REPLACE function, which REPLACE does not support.  dqmq and I sidestep that by converting the text value to a varchar(max) first.

:)
0
 
NorieVBA ExpertCommented:
Yes, I realised the error message wasn't down to the single quote after reading the other posts.
0
 
goodluck11Author Commented:
>or the better long term solution: permanently convert the column to varchar(max)

But this has an 8,000 char limitation correct ?
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
Yes. Varchar(max) is the same as varchar(8000). And if you ever import/export using excel varchar(8000) is actually better as max does funny things sometimes.
0
 
NorieVBA ExpertCommented:
How many characters do you have in the field?
0
 
goodluck11Author Commented:
these are long html files... text would be best ?
0
 
dqmqCommented:
>Varchar(max) is the same as varchar(8000).

That is not true.  Varchar(max) can hold up to 2GB and is not subject to the numerous limitations of text.  Also, the text datatype has been deprecated and MS has announced their intention to drop it in some unspecified future release.
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
I stand corrected
http://msdn.microsoft.com/en-us/library/ms176089.aspx

Apparently it's been that way since mssql 2005 and I never notice the change. Nice to lean something new.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.