| Author: Sonu Fernandes 21 May 2008 | Member Level: Gold Points : 2 |
Question: How to use "Like" Condition in sql server?
Answer: In SQL Server Like is a Clause which is used to match the String Pattern in a Database Table and it has one condition without using where clause and wildcards Like clause will not work.
we have 4 types of wildcards 1. %(percentage sign) 2. _(underscore sign) 3. [ ](square bracket sign) 4. [^](square bracket with not sign)
Suppose you have an Employee table and you want the employee name which starts with R Character
select * from employee where emp_name like'r%' it will retrieve all the employee name starts with R character just put the wildcard sign after the character. Output:- Rajan
Suppose you want the employee name which end the the R character Select * from employee where emp_name like'%r" just put the wildcard sign before the character. Output:- kumar
Suppose you want the employee name starts with R and end with N character Select * from employee where emp_name like'%r_%n' Output:- Rajan
For more information visit this site:- 1. http://www.sql-tutorial.net/SQL-LIKE.asp 2. SQL Server Book Online
|