SQL RTRIM Function

Example

Remove trailing spaces from a string:

SELECT RTRIM('SQL Tutorial     ') AS RightTrimmedString;

Definition and Usage

The RTRIM() function removes trailing spaces from a string.

Note: Also look at the LTRIM() function.

Syntax

RTRIM(string)

Continue reading SQL RTRIM Function

SQL RIGHT Function

Example

Extract 3 characters from a string (starting from right):

SELECT RIGHT('SQL Tutorial', 3) AS ExtractString;

Definition and Usage

The RIGHT() function extracts a number of characters from a string (starting from right).

Syntax

RIGHT(string, number_of_chars)

Continue reading SQL RIGHT Function

SQL REVERSE Function

Example

Reverse a string:

SELECT REVERSE('SQL Tutorial');

Definition and Usage

The REVERSE() function reverses a string and returns the result.

Syntax

REVERSE(string)

Continue reading SQL REVERSE Function

SQL REPLICATE Function

Example

Repeat a string:

SELECT REPLICATE('SQL Tutorial', 5);

Definition and Usage

The REPLICATE() function repeats a string a specified number of times.

Syntax

REPLICATE(string, integer)

Continue reading SQL REPLICATE Function

SQL REPLACE Function

Example

Replace “T” with “M”:

SELECT REPLACE('SQL Tutorial', 'T', 'M');

Definition and Usage

The REPLACE() function replaces all occurrences of a substring within a string, with a new substring.

Note: The search is case-insensitive.

Tip: Also look at the STUFF() function.

Syntax

REPLACE(string, old_string, new_string)

Continue reading SQL REPLACE Function

SQL QUOTENAME Function

Example

Return a Unicode string with bracket delimiters (default):

SELECT QUOTENAME('abcdef');

Definition and Usage

The QUOTENAME() function returns a Unicode string with delimiters added to make the string a valid SQL Server delimited identifier.

Syntax

QUOTENAME(string, quote_char)

Continue reading SQL QUOTENAME Function

SQL PATINDEX Function

Example

Return the position of a pattern in a string:

SELECT PATINDEX(‘%schools%’, ‘iampsp.com’);

Definition and Usage

The PATINDEX() function returns the position of a pattern in a string.

If the pattern is not found, this function returns 0.

Note: The search is case-insensitive and the first position in string is 1.

Syntax

PATINDEX(%pattern%, string)

Continue reading SQL PATINDEX Function

SQL NCHAR Function

Example

Return the Unicode character based on the number code 65:

SELECT NCHAR(65) AS NumberCodeToUnicode;

Definition and Usage

The NCHAR() function returns the Unicode character based on the number code.

Syntax

NCHAR(number_code)

Continue reading SQL NCHAR Function

SQL LTRIM Function

Example

Remove leading spaces from a string:

SELECT LTRIM('     SQL Tutorial') AS LeftTrimmedString;

Definition and Usage

The LTRIM() function removes leading spaces from a string.

Note: Also look at the RTRIM() function.

Syntax

LTRIM(string)

Continue reading SQL LTRIM Function

SQL LOWER Function

Example

Convert the text to lower-case:

SELECT LOWER('SQL Tutorial is FUN!');

Definition and Usage

The LOWER() function converts a string to lower-case.

Note: Also look at the UPPER() function.

Syntax

LOWER(text)

Continue reading SQL LOWER Function