Technical Article

Trim Left Char (for single words)

,

SELECT Result = dbo.TrimLeftChar('.','.............Adrian')

CREATE FUNCTION    [dbo].[TrimLeftChar]( @CharToTrim AS CHAR(1) ,
                                       @String AS VARCHAR(MAX) 

 ) RETURNS VARCHAR(MAx)

AS

BEGIN

    RETURN REPLACE( LTRIM( REPLACE(@String, @CharToTrim,' ')), ' ', @CharToTrim)

    -- Replace the char to be trimed with spaces. If we want to trim 0

  -- '0001234056000' will become ' 1234 56 '

    -- Trim the left spaces. ' 1234 56 ' will become '1234 56 '

    -- Restore the non trimed spaces with its original value.

    -- '1234 56 ' will become '1234056000'
  
  -- As you can see it only works nice for single text. but i migth useful
  -- to you in a particular situation.
END

Rate

3 (4)

You rated this post out of 5. Change rating

Share

Share

Rate

3 (4)

You rated this post out of 5. Change rating