Powered by Blogger.

Saturday, February 15, 2014

Like operator examples in SQL Server 2008



In this post we will discuss about some examples of Like operator in Sql Server 2008.

You can also check my previous posts on Working with enterprise library for data access in asp.net Part-3 [Read here], WCF tutorial and example in C#.Net and Left outer join and Right outer join in SQL Server.

Below are some example of Like statement in SQL Server:

Example-1:
The below statement will return record whose FirstName starts with B, like Bijay, Biju etc.

SELECT * FROM Employees WHERE FirstName LIKE 'B%'

Example-2:
The below statement will return record whose FirstName ends with B, like TamannaA

SELECT * FROM Employees WHERE FirstName LIKE '%A'

Example-3:
The below statement will return record whose FirstName contains word JA, like BiJAy, SanJAy etc.

SELECT * FROM Employees WHERE FirstName LIKE '%JA%'

Example-4:
The below statement will return record whose FirstName starts with A,B,C or D. like Ajay, Bijay, China, Denmark etc.

SELECT * FROM Employees WHERE FirstName LIKE '[abcd]%'

Example-5:
The below statement will return record whose FirstName starts between B to T like
Bijay
Sanjay
Tanmayee
Tamanna

SELECT * FROM Employees WHERE FirstName LIKE '[B-t]%'





0 comments

Post a Comment