Monday, August 2, 2010

MS-SQL - User Defined Trim Function in MS-SQL


Trim function


CREATE FUNCTION Dbo.Trim(@TextValue NVARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
    BEGIN
        DECLARE @TValue NVARCHAR(MAX)
        
            SET @TValue=LTRIM(RTRIM(@TextValue))
            
            RETURN (@TValue)
    END     

GO 

Calling Function

   1:  SELECT Dbo.Trim('   MS-SQL   ')

Download
Download Script

No comments:

Post a Comment