Monday, September 28, 2015

trim function in SQL Server

TRIM function is used to removed the space of given strings.

Two types of TRIM function. i.e.

1.       RTRIM function
2.       LTRIM function

The RTRIM function is used to remove the right side space of given string.
The LTRIM function is used to remove the left side space of given string.

The query using  LTRIM and RTRIM as given below.

ALTER FUNCTION [dbo].[TRIM_STRING](@TEXT_STRING NVARCHAR(MAX))

RETURNS NVARCHAR(MAX)

BEGIN
     RETURN LTRIM(RTRIM(@TEXT_ STRING))
END