0 Replies - 1612 Views - Last Post: 18 April 2008 - 05:34 AM

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

User defined function for trimming leading & trailing spaces in MSSQL

Posted 18 April 2008 - 05:34 AM

Description: Pass the function the value you wish to have trimmedThis a user defined function I created for trimming leading & trailing spaces off a value. It's easier and simpler for me than using RTRIM(LTRIM(@value))
CREATE FUNCTION dbo.udfTrimString (@value VARCHAR(8000))
RETURNS VARCHAR(8000)

AS
	BEGIN
		--variable to hold the final result
		DECLARE @Trimmed_Value VARCHAR(8000)
		--user LTRIM & RTRIM to set the vaoue of our final result
		SET @Trimmed_Value = RTRIM(LTRIM(@value))
		--return the trimmed string
		RETURN @Trimmed_Value
	END


Is This A Good Question/Topic? 0
  • +

Page 1 of 1