SQL SPACE Function

Example

Return a string with 10 spaces:

SELECT SPACE(10);

Definition and Usage

The SPACE() function returns a string of the specified number of space characters.

SPACE(number)

Continue reading SQL SPACE Function

SQL SOUNDEX Function

Example

Evaluate the similarity of two strings, and return a four-character code:

SELECT SOUNDEX('Juice'), SOUNDEX('Jucy');

Definition and Usage

The SOUNDEX() function returns a four-character code to evaluate the similarity of two expressions.

Note: The SOUNDEX() converts the string to a four-character code based on how the string sounds when spoken.

Tip: Also look at the DIFFERENCE() function.

Syntax

SOUNDEX(expression)

Continue reading SQL SOUNDEX Function

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