Skip to content

STRING FUNCTIONS :

ASCII :

Returns the ASCII value for the specific character

1
2
3
4
5
6
7
8
select ascii('A')

 RETURNS 65 AS RESULT
 ```

 ### CHAR :

Returns the character based on the ASCII code

select char(65)

returns 'A' as result

1
2
3
### CHARINDEX :

Returns the position of a substring in a string

SELECT charindex('t',ename) from emp

1
2
3
### CONCAT :

Adds two or more strings together

SELECT concat(fisrtname,lastname) from radsch_orders

1
2
### UPPER :
Convert the text to upper-case

SELECT UPPER(ename) from emp

1
2
### LOWER :
Convert the text to lower-case

select LOWER(ename) from emp

1
2
### left :
The LEFT() function extracts a number of characters from a string (starting from left)

select left(ename,3) from emp

1
2
### RIGHT :
The RIGHT() function extracts a number of characters from a string (starting from right)

select right(ename,3) from emp

1
2
### PATINDEX :
Return the position of a pattern in a string:

SELECT patindex('%mi%',ename) from emp

1
2
### LEN :
Return the length of a string

Select len(eame) from emp

1
2
3
### SUBSTRING :

The SUBSTRING() function extracts some characters from a string.

select (columnname,startingposition,no.of charecters)

select (ename,1,5) from emp

1
2
### STUFF :
The STUFF() function deletes a part of a string and then inserts another part into the string, starting at a specified position. 

select stuff(coumnname,startingposition,no.of cahrecters,replacestring)

select stuff(ename,1,3,'chi') from emp

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

select replace(columnname,serchstring,replacestring)

select replace(ename,'smi','chi')

1
2
### REVERSE :
The REVERSE() function reverses a string and returns the result.

select reverse(columnname)

select reverse(ename) from emp

1
2
### REPLICATE :
The SQL REPLICATE is a SQL String Function used to repeat the existing string for a given number of times. 

SELECT replicate(columnname,no.of times to replicate)

select replicate(columnname,2)

1
2
### LTRIM :
LTRIM() function helps to return remove all the space characters found on the left-hand side of the string

SELECT ltrim(columnname)

select ltrim(ename) from emp

1
2
### Rtrim :
RTRIM() function helps to return remove all the space characters found on the Right-hand side of the string

select rtrim(columname)

select rtrim(ename) from emp ```