Share Blog

Monday, May 19, 2014

WildCard Operator in SQL Server

DESCRIPTION

The SQL LIKE condition allows you to use wildcards to perform pattern matching. The LIKE condition is used in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.
A wildcard character can be used to substitute for any other character(s) in a string.
wildcard characters are used with the SQL LIKE operator.
SQL wildcards are used to search for data within a table.

PARAMETERS OR ARGUMENTS

expression is a character expression such as a column or field.

pattern is a character expression that contains pattern matching. The patterns that you can choose from are:
  • % allows you to match any string of any length (including zero length)
  • _ allows you to match on a single character
escape_character is optional. It allows you to test for literal instances of a wildcard character such as % or _.
------Create  Table Emp1-------

create Table Emp1(id int primary key,name varchar(50),email varchar(50))
insert into emp1 values(1,'sunil','sunil@gmail.com'),(2,'naveen','naveen@gmail.com'),(3,'shivam','shivam@gmail.com')




select name from emp1 
where name LIKE '%e__%'

select name from emp1
where name NOT LIKE '%bc__%'

select name from emp1
where name LIKE '[__n]%'

select id from Emp1
where NAME  like'[a-z]%'

select name from emp1
where NAME like '%__r%'

No comments:

Post a Comment