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 VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
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
SQL 2016 DESIGN & PROGRAMMING
 
 
 
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