Like Operator in Sql Server Example:-
- It is used to compare column value with character patterns.
Syntax: Like’pattern’
Not like ‘pattern’.
- The pattern consists of a-z , 0-9,
- Metacharacters -> % (this is to replace none (or) meta characters).
- _ [Under score] -> to replace exactly one character
- [ ] -> to replace range (or) set of characters
Display employee records name starts with ‘S’
- Select * from emp Where ename like’S%’
Name ends with ‘S’
- Select * from emp Where ename like ‘%S’.
Name starts with ‘S’& ends with ‘S’
- Select * from emp Where ename like ‘S%S’
If ‘S’ contain any place:
- Select * from emp Where ename like ‘%S%’.
Where ‘a’ is the second character in the name
- Select * from emp Where ename like’-a’
Display employee records name starts between a and p.
- Select * from emp Where ename ,like ‘[a-p]%’
Where name doesn’t start with a and p
- Select * from emp Where ename like ‘[^ a-p]%’ (or) Not like ‘[a-p]%’.
Display employee records names starts with
A (or) b (or) s (or) t
- Select *from emp Where ename like’[abst]%’
- Select * from emp Where ename like ‘[^abst]%’
Escape Operator in Sql Server :-
Display the _names
- Select * from emp Where ename like ‘%\_%’
- Escape ‘\’.
Use escape option the string contains metacharacter.
Is Operator in Sql Server :-
- Used to compare column value with null (or)not null
Syntax :
Is null
Is not null
”Display emplist whose commission is NULL”
- Select * from emp Where comm. Is null
- Select * from emp Where comm. Is not null.