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
 Old Forums
 CLOSED - General SQL Server
 remove tab or space character from a string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-30 : 09:39:12
Roxanne writes "Hello:
I hope you can help me out. I have a table with over 400,000 recordsets. one of the fields named DESCRIPTION has some tab characters in it--it is a varchar, 500. I want to remove the tab characters from the description fields that have them. Any advice?

Thanks alot!
Roxanne"

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-30 : 09:51:33
Look up REPLACE in Books OnLine ....

Jay White
{0}
Go to Top of Page

scottpt
Posting Yak Master

186 Posts

Posted - 2002-07-30 : 10:05:47

DECLARE @note varchar(255),
@start int,
@tempnote varchar(255)
@temp cahr(1)



set @start=CHARINDEX(char(34),@note)
set @tempnote=substring(@note,1,(@start-1)) + ' '

While len(@note) > @start
begin
set @temp=substring(@note,@start,1)

IF @temp <> char(34)
begin
set @tempnote=@tempnote + @temp
end
else
begin
set @tempnote=@tempnote + ' '
end


SET @start=@start+1
end

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-30 : 10:14:58
scottpt, I hate to be picky . . .
1.) char(34) is a " . . . I think you meant char(9) for TAB . . .
2.) this iterative method is going to be quite slow going through a table with 400,000 rows. You will have to populate @note (which you have as a varchar(255), when the poster said it was a varchar(500)) with each record, one at a time. This simply won't scale well . . .

A much more 'SQLicious' approach would be...

update Roxanne
set description = replace(description,char(9),'')

 


Jay White
{0}
Go to Top of Page
   

- Advertisement -