Triming any String in Sql Server.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 304
We will create a function called Trim as below and use the Ltrim and Rtrim in-built Sql Server function.

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [TRIM](@string VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@string))
END


To use,
SELECT dbo.TRIM(' sample text Here ');

Comments or Responses

Login to post response