I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the LTRIM() function today.
The LTRIM() function takes a source string as input and returns a output string with all leading spaces removed.
The following example removes leading spaces from a favorite movie title of mine.
1 2 |
-- Remove leading spaces select ltrim(' WIZARD OF OZ') as str_phrase |
1 2 3 4 5 |
output: str_phrase ------------ WIZARD OF OZ |
One thing to always worry about when using TSQL functions is how will it react with empty strings or NULL values? Both empty strings and NULL values as input return themselves as output.
1 2 3 4 5 |
-- Empty string returns empty string select ltrim('') as str_phrase -- Null returns Null select ltrim(NULL) as str_phrase |
1 2 3 4 5 6 7 8 |
output: str_phrase ---------- str_phrase ---------- NULL |
Next time, I will be exploring the NCHAR() function.