Wednesday, December 25, 2024

SQL Server LTRIM() Function

 The LTRIM() function in SQL Server is used to remove leading spaces (i.e., spaces at the beginning of a string) from a given string.

Syntax:

LTRIM(string)
  • string: The string expression from which leading spaces will be removed.

Example:

SELECT LTRIM('   Hello World') AS Result;

Output:

Result
--------
Hello World

In this example, LTRIM() removes the spaces before the word "Hello" and returns "Hello World".

Note that LTRIM() only removes leading spaces. To remove trailing spaces (spaces at the end of a string), you would use the RTRIM() function. If you need to remove both leading and trailing spaces, you can use TRIM() (available in SQL Server 2017 and later).

No comments:

Post a Comment