Hello Friends, In this tutorial we are going to Learn Operator in SQL Server. Like Operator is used to perform a pattern matching search in a Query.
Like Operator in SQL Server:
Like Operator is used to perform a pattern matching search in a Query. Like Operator is used in the where clause of select, Insert, update and delete statement.
Syntax:
The Syntax for using Like Operator in SQL Server.
expression LIKE pattern [ ESCAPE ‘escape_character’ ]
Where;
expression specified columns on which you want to perform Pattern matching search.
pattern specified the wild cards. There is two wild card used with like operator:
%: allows you to match string of any length (including zero)
_: allows you to match on a single character.
ESCAPE ‘escape_character’
Optional. It allows you to pattern match on literal instances of a wildcard character such as % or _.
Like Operator with SELECT Statement:
First of all create a table and insert few demo Records:
Create Table: CREATE TABLE [dbo].[Employee]( [EmployeeID] [bigint] IDENTITY(1,1) NOT NULL, [EmployeeName] [varchar](100) NULL, [Designation] [varchar](50) NULL, [Salary] [float] NULL, [City] [varchar](100) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO
Insert Records:
INSERT [dbo].[Employee] ([EmployeeID], [EmployeeName], [Designation], [Salary], [City]) VALUES (1, N'Ahwin Roy', N'Software Engineer', 800000, N'Varanasi') GO INSERT [dbo].[Employee] ([EmployeeID], [EmployeeName], [Designation], [Salary], [City]) VALUES (2, N'Ritesh Shah', N'Team Leader', 900000, N'New Delhi') GO INSERT [dbo].[Employee] ([EmployeeID], [EmployeeName], [Designation], [Salary], [City]) VALUES (3, N'Vikas Gupta', N'DBA', 1200000, N'Allahabad') GO INSERT [dbo].[Employee] ([EmployeeID], [EmployeeName], [Designation], [Salary], [City]) VALUES (4, N'Akash Tripathi', N'Tester', 700000, N'Mumbai') GO INSERT [dbo].[Employee] ([EmployeeID], [EmployeeName], [Designation], [Salary], [City]) VALUES (5, N'Nitin Pandey', N'Web Developer', 8000000, N'Pune') GO SET IDENTITY_INSERT [dbo].[Employee] OFF GO Example 1:
Example 1:
The Following query will all Employees with an EmployeeName starting with “v”.
SELECT * FROM [dbo].[Employee] WHERE [EmployeeName] LIKE 'v%'
Example 2:
The Following query will all Employees with an EmployeeName ending with “a”.
SELECT * FROM [dbo].[Employee] WHERE [EmployeeName] LIKE '%y'
Example 3:
The following query will all Employees whose EmployeeName contains “in” at any position
SELECT * FROM [dbo].[Employee] WHERE [EmployeeName] LIKE '%in%'
Example 4:
The following query will all Employees with a City of length 4 ended with “e”
SELECT * FROM [dbo].[Employee] WHERE [EmployeeName] LIKE '___e'
Example 5:
The following query will all Employees with a City of length 6 with “M” at its first and “M” at its third position
SELECT * FROM [dbo].[Employee] WHERE [City] LIKE 'M_m___'
View More:
- Check Constraint in SQL Server to allow only Alphabates in Column.
- Triggers in SQL Server.
- Create Table Statement in SQL Server.
- Union and Union All in SQL Server.
Conclusion:
I hope you understand how to use Like Operator in SQL Server. I would like to have your feedback, comments and suggestions.
Thank You.
mail order pharmacy pharmacy drugstore online canada drug pharmacy
canada drug pharmacy pharmacy express the pharmacy
discount pharmacy card mexican pharmacy pharmacy express
online pharmacy erectile dysfunction treatment e d
my canadian pharmacy pharmacy rx world drug rx
Today, I went to the beachfront with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!
I loved as much as you’ll receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an shakiness over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly very often inside case you shield this hike.|
Hello, I desire to subscribe for this blog to take most recent updates, thus where can i do it please help out.|
Howdy, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam remarks? If so how do you protect against it, any plugin or anything you can recommend? I get so much lately it’s driving me mad so any assistance is very much appreciated.|
Hello excellent blog! Does running a blog similar to this require a lot of work? I’ve no knowledge of programming but I had been hoping to start my own blog soon. Anyways, if you have any suggestions or tips for new blog owners please share. I know this is off subject nevertheless I just needed to ask. Kudos!|
I don’t even understand how I finished up right here, but I assumed this put up used to be great. I don’t recognise who you are but definitely you’re going to a well-known blogger in case you are not already. Cheers!|
Howdy! I’m at work surfing around your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the outstanding work!|
I am really grateful to the holder of this web site who has shared this great post at here.|