trim ms sql code example

Example 1: trim sql

SELECT TRIM('   Exemple   ');						-- 'Exemple'
SELECT LTRIM('   Exemple   ');						-- 'Exemple   '
SELECT RTRIM('   Exemple   ');						-- '   Exemple'
SELECT TRIM(BOTH 'x' FROM 'xxxExemplexxx');			-- 'Exemple'
SELECT TRIM(LEADING 'x' FROM 'xxxExemplexxx');		-- 'Exemplexxx'
SELECT LTRIM('xxxExemplexxx', 'x');					-- 'Exemplexxx'
SELECT TRIM(TRAILING 'x' FROM 'xxxExemplexxx'); 	-- 'xxxExemple'
SELECT RTRIM('xxxExemple', 'x');					-- 'Exemplexxx'

Example 2: SQL SERVER 2016 TRIM

-- Syntax for SQL Server and Azure SQL Database
TRIM ( [ characters FROM ] string )

Tags:

Sql Example