Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing spaces from fields

Status
Not open for further replies.

impulse24

IS-IT--Management
Joined
Jul 13, 2001
Messages
167
Location
US
Hi,

What is the update statement I would use to clear out spaces out of fields? I have a database with over 2M records, and all of the fields of data have extra spaces. I have tried:

Update pages
set index1 = RTrim(index1)

and I just keep getting a TimeOut error. Is the above the correct syntax? And if so how do i get aroung the timeout error.

Each record is entirely unique, and all the fields of a record have different values. So I cant do a subset of records. Can anyone help.
 
You can do batches of updates. The following script shows how to update 20000 records at a time until all records are updated and trailing spaces removed. You can increase or decrease the number of records affected as needed for your purposes.

-- declare variable to control looping
Declare @rc int
Set @rc=1

-- Set maximum number of rows affected by Update
Set rowcount 20000

-- Create While loop
While @rc>0
Begin

Begin Transaction

-- Only update records that have trailing spaces
Update Pages
Set index1 = RTrim(index1)
Where right(index1,1)=' '

-- Store number of records updated
Set @rc = @@rowcount
Select RowsUpdated=@rc

-- Commit Transaction to clear transaction log
Commit Transaction

End Terry L. Broadbent
Programming and Computing Resources
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top