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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

goodluck11Author Commented:
this is on SQl server 2008
0
Patrick MatthewsCommented:
Convert the text before doing the replace:

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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dqmqCommented:
This might work:

UPDATE table1
SET description = cast(REPLACE(cast([description] as varchar(max)), '''', '') as text) where username ='user123'
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

dqmqCommented:
or the better long term solution: permanently convert the column to varchar(max)
0
NorieAnalyst Assistant Commented:
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
NorieAnalyst Assistant Commented:
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
NorieAnalyst Assistant Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.