I have a table in a SQL Server 2008 database. This table has a nvarchar(256) column called \'Name\'. Unfortunately, the values in this field have extra spaces included. For
This function trims a string from left and right. Also it removes carriage returns from the string, an action which is not done by the LTRIM and RTRIM
IF OBJECT_ID(N'dbo.TRIM', N'FN') IS NOT NULL
DROP FUNCTION dbo.TRIM;
GO
CREATE FUNCTION dbo.TRIM (@STR NVARCHAR(MAX)) RETURNS NVARCHAR(MAX)
BEGIN
RETURN(LTRIM(RTRIM(REPLACE(REPLACE(@STR ,CHAR(10),''),CHAR(13),''))))
END;
GO