3.2.09

Like operator in SQL Server

Pattern matching in SQL Server:

Pattern matching is a very good area and its very well needed for searching our related data in our database. Considering, I need to check the person name starts with A. In this case, we can opt like operator in SQL Server to retrieve those related patterns.

Below is an example,


drop table venkat
create table venkat(id int, name varchar(10))
insert into venkat
select 1,'Venkat'
union all
select 2,'arun'
union all
select 3,'Lakshmi'
union all
select 4,'arun'
union all
select 5,'ve'

Let's see some of the pattern mathching conditions


String Starts with "V" and having any number of characters. % indicates any number of character
select * from venkat where name like 'V%' - No ouput
String Starts with "V" and having only one character. _ indicates only one number.
select * from venkat where name like 'V_' - 5 for id and ve for name
String should not start with "V"
select * from venkat where name not like 'V%'

Happy Learning!!!
Regards,
Venkatesan Prabu .J

No comments:

Post a Comment