Transact SQL Other Articles Software Reviews
Trimming Strings in Transact-SQL
The Transact SQL LTrim and RTrim functions can be used to remove spaces from the left and right sides of a string, respectively. As such it can be used to ensure that data entered into a table does not contain any additional whitespace that could cause future issues of data quality.
For example, this stored procedure removes trailing whitespace from the input RegionDescription using RTrim:
CREATE PROCEDURE InsertRegion
Unlike many programming languages, Transact-SQL does not have a function to remove whitespace from both left and right sides of the string simultaneously. If this is required, it is possible to use a nested function calling both LTrim and RTrim: