SELECT Result = dbo.TrimLeftChar('.','.............Adrian')
Detective Stories - Changing the Case
How to change your "UPPER" or "lower" case strings to a mixed case
2010-10-18
6,091 reads
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