Instagram
youtube
Facebook
Twitter

MS SQL Server LIKE Operator

MS SQL Server LIKE Condition

  • LIKE condition is used with the WHERE clause to perform pattern matching.
  • Syntax:
expression LIKE pattern
  • list of patterns used with LIKE:
Wildcard Explanation
 %  Represent zero or more characters
 - Represent a single character
 [ ] Represent any character in the [ ] brackets

LIKE operator using % wildcard

SELECT * FROM [University].[dbo].[Student] WHERE Name LIKE 'S%';
Id Name Branch CGPA
EN19CS301254 Sneha CSE 9.34
EN19CS301246 Savi CSE 8.23

LIKE operator using _ wildcard

SELECT * FROM Student WHERE Name LIKE '_avi';
Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.34
EN19CS301246 Savi CSE 8.23

LIKE Operator using [ ] wildcard

SELECT * FROM Student WHERE Name LIKE '[RS]avi';
Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.34
EN19CS301246 Savi CSE 8.23

LIKE Operator with NOT Operator

​SELECT * FROM [University].[dbo].[Student] WHERE Name NOT LIKE'S%';

​
Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.34
EN19CS301248 Aayush CSE 7.25
EN19CS301258 Kavi NULL NULL