SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Removing Carriage Returns in a Select Statement


Removing Carriage Returns in a Select Statement

Author
Message
wfbojar
wfbojar
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 4
Hello!



I have an address column that is of ntext data type. There are carriage returns in the data that I need to remove during a select statement. I've tried to do a REPLACE function by replacing chr(13) with null. That didn't work so I just tried to replace an 'a' with an 'A' (REPLACE(Address, 'a', 'A')) and got the same error: "Argument data type ntext is invalid for argument 1 of replace function." I ran the exact syntax on a column that was not an ntext and it worked just fine. It seems that SQL Server doesn't like that replace function on ntext data types.



Is there something I'm missing or is there another way of doing this?



Thanks!

-Bill
Andras Belokosztolszki
Andras Belokosztolszki
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2965 Visits: 1585
Hi Bill,

this is unfortunately a limitation of the LOB (text, ntext and image) datatypes. This has been improved in 2005 with the new LOM data types ([n]varchar(max) and varbinary(max)), but in 2000 you will still need to use TEXTPTR and UPDATETEXT http://msdn2.microsoft.com/en-us/library/ms189466.aspx



Regards,

Andras



Andras Belokosztolszki, MCPD, PhD
GoldenGate Software
Andras Belokosztolszki
Andras Belokosztolszki
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2965 Visits: 1585
As a follow up, if your LOB data is smaller than 8000 bytes, you could of course convert it to varchar(8000) and do a replace on that.



To see an example how to do replace using the UPDATETEXT have a look at http://sqlserver2000.databases.aspfaq.com/how-do-i-handle-replace-within-an-ntext-column-in-sql-server.html



It may of course be easier to write a small external application (text, ntext and image columns are really a pain)



Regards,

Andras



Andras Belokosztolszki, MCPD, PhD
GoldenGate Software
wfbojar
wfbojar
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 4
Thanks Andras! I'll try that. I am going to be in the process of converting this database over to 2005 so it seems that it will be easier in there.



-Bill
Lowell
Lowell
SSC-Dedicated
SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)

Group: General Forum Members
Points: 37099 Visits: 40280
here's a find and replace for a TEXT field in SQL 2000;

in this example, i'm replacing a relative link with a full link, so it's a good example:



DECLARE @reviewid int, @ptr binary(16), @idx int

SET @reviewid = 0

SELECT TOP 1 @reviewid = reviewid, @idx = PATINDEX('%href="reviews%',review_body) - 1

FROM reviews

WHERE PATINDEX('%href="reviews%',review_body) > 0

WHILE @reviewid > 0

BEGIN

SELECT @ptr = TEXTPTR(review_body)

FROM reviews

WHERE reviewid = @reviewid

UPDATETEXT reviews.review_body @ptr @idx 13 'href="http://www.somewebsite.com/reviews'

SET @reviewid = 0

SELECT TOP 1 @reviewid = reviewid, @idx = PATINDEX('%href="reviews%',review_body)-1

FROM reviews

WHERE reviewid > @reviewid

AND PATINDEX('%href="reviews%',review_body) > 0

END

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search