Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 update text performance

Author  Topic 

dupati1
Posting Yak Master

123 Posts

Posted - 2005-11-03 : 09:29:49
Guys,

I came up with this below sp to replace nonascii characters in the text field with single space...


CREATE PROCEDURE myproc    
@WBS1 varchar(30),
@DescCategory varchar(10)

AS

declare @ptr binary(16) ,
@i int ,
@datalen int ,
@DelPos int
, @Char int

Declare MyCursor CURSOR for
select WBS1, DescCategory from mytable
where WBS1 Like @WBS1
And DescCategory Like @DescCategory
AND PATINDEX('%[^a-zA-Z0-9]%',Description)<> 0
open MyCursor

FETCH NEXT FROM MyCursor into @WBS1, @DescCategory

WHILE @@FETCH_STATUS = 0
BEGIN


select @i = 0
, @datalen = datalength(Description)
from mytable where
DescCategory = @DescCategory
and WBS1 = @WBS1

while @i < @datalen
begin
select @DelPos = @i
select @i = @i + 1
Select @Char = ascii(substring(Description,@i,1))
from mytable
where WBS1 = @WBS1
and DescCategory = @DescCategory

if @Char < 32 or @Char = 255
begin
select @ptr = textptr(Description)
from mytable where
DescCategory = @DescCategory
and WBS1 = @WBS1
updatetext
mytable.Description
@ptr
@DelPos
1
' '
end
end
FETCH NEXT FROM MyCursor into @WBS1, @DescCategory
END

CLOSE MyCursor
DEALLOCATE MyCursor

GO


AS you can see i am going through character by character in the text field for each record...which is taking lot of time...

Do you guys have any suggestions for better performance...

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-03 : 09:37:42
This does a search and replace which should be much faster.
http://www.mindsdoor.net/SQLTsql/ReplaceText.html
Just change @old to be something like '[^0-9a-zA-Z ]' or whatever you like
maybe
'[' + char(32) + '-' + char(255) + ']'
Don't know if that would work.
and @new to ''




==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

dupati1
Posting Yak Master

123 Posts

Posted - 2005-11-03 : 11:58:57
nr...thanks for the link...i tried the code and i think it worked to a point and throwed the following error...

Deletion length 12 is not in the range of available text, ntext, or image data.
The statement has been terminated.

i used the following...

select @old = '[\f\r\v\t\n]' ,
@new = ' '


and select @dellen = len(@old) is set as per your code...is that what it is complaining about??


Thanks
Go to Top of Page
   

- Advertisement -