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)
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)
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…
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)
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)
Example Reverse a string: SELECT REVERSE(‘SQL Tutorial’); Definition and Usage The REVERSE() function reverses a string and returns the result. Syntax REVERSE(string)
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)
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()…
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)
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…
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)