Hi All,
Hope you all are doing good.
In this article, we will know about various T-SQL string functions and their uses.
Please go through below table to understand each string function.
Thanks for reading my article.
Hope you all are doing good.
In this article, we will know about various T-SQL string functions and their uses.
Please go through below table to understand each string function.
Method Name | Description | Syntax | Example | Output |
ASCII | Returns the ASCII code of the given character. | ASCII(Character_Expression) | SELECT ASCII('A') | 65 |
CHAR | Converts an int ASCII code to a character. Note: integer should be between 0 and 255. | CHAR(Integer_Expression) | SELECT CHAR(255) | ÿ |
REVERSE | Reverses all the characters in the given string. | REVERSE('Any_String_Expression') | SELECT REVERSE('SUNEEL') | LEENUS |
LEN | Returns the count of total characters in the given string expression | LEN(String_Expression) | SELECT LEN('SUNEEL KUMAR') | 12 |
LOWER | Converts all the characters in the given Character_Expression into lowercase letters. | LOWER(Character_Expression) | SELECT LOWER('SUNEEL') | suneel |
UPPER | Converts all the characters in the given Character_Expression intto uppercase letters. | UPPER(Character_Expression) | SELECT UPPER('suneel') | SUNEEL |
RTRIM | Removes blanks on the right hand side of the given character expression. | RTRIM(Character_Expression) | SELECT RTRIM('SUNEEL ') | SUNEEL |
LTRIM | Removes blanks on the left handside of the given character expression. | LTRIM(Character_Expression) | SELECT LTRIM(' SUNEEL') | SUNEEL |
LEFT | Returns the specified number of characters from the left hand side of the given character expression. | LEFT(Character_Expression, Integer_Expression) | SELECT LEFT('ABCDE', 3) | ABC |
RIGHT | Returns the specified number of characters from the right hand side of the given character expression. | RIGHT(Character_Expression, Integer_Expression) | SELECT RIGHT('ABCDE', 3) | CDE |
CHARINDEX | Returns the starting position of the specified expression in a character string. Start_Location parameter is optional. | CHARINDEX('Expression_To_Find', 'Expression_To_Search', 'Start_Location') | SELECT CHARINDEX('@','suneel@suneel.com',1) | 7 |
SUBSTRING | This function returns substring (part of the string), from the given expression. | SUBSTRING('Expression', 'Start', 'Length') | SELECT SUBSTRING('suneel@suneel.com',6, 7) | l@sunee |
REPLICATE | Repeats the given string, for the specified number of times. | REPLICATE(String_To_Be_Replicated, Number_Of_Times_To_Replicate) | SELECT REPLICATE('Suneel ', 3) | Suneel Suneel Suneel |
SPACE | Returns number of spaces, specified by the Number_Of_Spaces argument. | SPACE(Number_Of_Spaces) | SELECT 'Suneel' + SPACE(5) + ' Kumar' | Suneel Kumar |
PATINDEX | Returns the starting position of the first occurrence of a pattern in a specified expression. It takes two arguments, the pattern to be searched and the expression. PATINDEX() is simial to CHARINDEX(). With CHARINDEX() we cannot use wildcards, where as PATINDEX() provides this capability. If the specified pattern is not found, PATINDEX() returns ZERO. | PATINDEX('%Pattern%', Expression) | SELECT PATINDEX('%@suneel.com', 'suneel@suneel.com') | 7 |
REPLACE | Replaces all occurrences of a specified string value with another string value. | REPLACE(String_Expression, Pattern , Replacement_Value) | SELECT REPLACE('suneel@suneel.com', '.com', '.net') | suneel@suneel.net |
STUFF | STUFF() function inserts Replacement_expression, at the start position specified, along with removing the charactes specified using Length parameter. | STUFF(Original_Expression, Start, Length, Replacement_expression) | SELECT STUFF('suneel@suneel.com', 3, 4, '*****') | su*****@suneel.com |
No comments:
Post a Comment