C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to use "Like" Condition in sql server


Posted Date: 15 May 2008    Resource Type: Code Snippets    Category: SQL
Author: mani kumar.k.mMember Level: Gold    
Rating: Points: 10



The following code shows How to use "Like" Condition in sql server

"Like" condition is used to match the column datas with the necessary

condition.

Consider my example i want to check for the names which starts with 'S' then

the query resembles as below,

select name from Table1 where name like 'S%'

Am trying to create a stored procedure to get the count with the column having

the word "Sri"


create procedure ImplementingLike

as begin

select count(*) from Table1 where Name like '%Sri%'

end








Responses

Author: Sonu Fernandes    21 May 2008Member 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



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Like Condition  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Simple example of full join and cross join
Previous Resource: How to view the user created tables in SQL Server
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use