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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 remove tab or space character from a string
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 07/30/2002 :  09:39:12  Show Profile  Visit AskSQLTeam's Homepage
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
Flowing Fount of Yak Knowledge

USA
2878 Posts

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

Jay White
{0}
Go to Top of Page

scottpt
Posting Yak Master

USA
186 Posts

Posted - 07/30/2002 :  10:05:47  Show Profile

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
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 07/30/2002 :  10:14:58  Show Profile
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
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000