–FOR SQL SERVER 2000:
CREATE FUNCTION dbo.TRIM(@string VARCHAR(8000)) RETURNS VARCHAR(8000) BEGIN RETURN LTRIM(RTRIM(@string)) END GO
–FOR SQL SERVER 2005:
CREATE FUNCTION dbo.TRIM(@string VARCHAR(MAX)) RETURNS VARCHAR(MAX) BEGIN RETURN LTRIM(RTRIM(@string)) END GO
Source: http://blog.sqlauthority.com/2007/04/24/sql-server-trim-function-udf-trim/
Last Updated on October 26, 2015