Like() function in SQL Server

Like:- This operator is used in a WHERE clause to search for a specific pattern in the values of the column.

In this article, we are going to use the following table for the examples:-

CREATE TABLE [dbo]. [Employee](
[Empid] [Int] IDENTITY (1, 1) NOT NULL Primary key,
[EmpNumber] [nvarchar](50) NOT NULL,
[EmpFirstName] [nvarchar](150) NOT NULL,
[EmpLAStName] [nvarchar](150) NULL,
[EmpEmail] [nvarchar](150) NULL,
[Salary] [int] NULL
)

We insert following data into the above tables:-

Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)
Values(‘A001′,’Vivek’,’Johari’,’samir@abcmail.com’,200000)

Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)
Values(‘A002′,’Amit’,’Kumar’,’amit@abcmail.com’,100000)

Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)
Values(‘A003′,’Neha’,’Sharma’,’neha@abcmail.com’,300000)

Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)
Values(‘A004′,’Nidhi’,’Sharma’,’nidhi@abcmail.com’,270000)
 

For example, suppose we want to get the records of the employee whose firstname start with character ‘N’, then we can use the below query:-

select * from employee where EmpFirstName  like ‘N%’

This query will returns the records for the employee whose empnumber is given below:

A003
A004

Again, suppose we want to get the records of the employees whose last name end with character ‘a’, then we can use the below query:-

Select * from employee where EmplastName  like ‘%a’

This query will returns the records for the employee whose empnumber is given below:-

A003
A004

Now, suppose we want to get the records of the employees whose last name contains character ‘ha’, then we can use the below query:-

select * from employee where EmplastName  like ‘%ha%’

This query will returns the records for the employees whose empnumber is given below:

A001
A003
A004

DMCA.com

About vivekjohari

Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on different databases like SQL Server, MySQL & Oracle, Azure SQL &  Big Data.
This entry was posted in SQL Functions, SQL Server and tagged . Bookmark the permalink.

31 Responses to Like() function in SQL Server

  1. Pingback: Moriah Israeli jewelry Collection

  2. Pingback: w88

  3. Pingback: Accountant in Vancoover WA

  4. Pingback: xembongdatructuyen

  5. Pingback: Manifestation Miracle

  6. Pingback: http://automag.com.pl/sport-223-2016-2125.php

  7. Pingback: افضل شركة تنظيف بالرياض

  8. Pingback: https://internetnews.net.pl/forum/nowe-technologie-f7/poznam-opinie-o-funkymedia-t62.html

  9. Pingback: https://biznesblog.biz.pl/forum/

  10. Pingback: forum

  11. Pingback: enlightened marketing

  12. Pingback: corn hole game

  13. Pingback: Samsara Market

  14. Pingback: Darknet Drogen

  15. Pingback: market research consultancy in india

  16. Pingback: m883d.com

  17. Pingback: lotto w88 truc tuyen

  18. Pingback: indoqq

  19. Pingback: www.jaguarqq1.site

  20. Pingback: ratu capsa

  21. Pingback: parisqq

  22. Pingback: pasarqq

  23. Pingback: login sbobet888

  24. Pingback: บาคาร่า

  25. Pingback: daftar warnetqq

  26. Pingback: ウォーターサーバー

  27. Pingback: ชุดไทยสวยๆ

  28. Pingback: cbd-campus

  29. Pingback: Royal Online v2

  30. Pingback: lycawatch

  31. Pingback: Fojart Marketing

Leave a Reply