DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to trailing spaces in a column with RTRIM?

The following Microsoft SQL Server T-SQL scripts update a column to remove trailing spaces:

-- SQL eliminate traliing spaces

UPDATE TableX

SET    ColumnA = RTRIM(ColumnA)

WHERE  len(ColumnA) > 0

       AND right(ColumnA,1) = ' '

 

 

-- SQL Server eliminate trailing spaces

USE Northwind;

UPDATE Customers

SET    Address = RTRIM(Address)

WHERE  len(Address) > 0

       AND right(Address,1) = ' '

-- (0 row(s) affected)

 

-- Add trailing spaces for testing purposes

UPDATE Customers

SET    Address = Address + '   '

WHERE  len(Address) > 0

-- (91 row(s) affected)

 

-- T-SQL truncate trailing spaces

UPDATE Customers

SET    Address = RTRIM(Address)

WHERE  len(Address) > 0

       AND right(Address,1) = ' '

-- (91 row(s) affected)

Related article:

RTRIM (Transact-SQL)

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE