September 3, 2011

Wildcard characters in SQL Server

We use wildcard characters with LIKE clause.There are four wildcard characters
in SQL Server.

(1) ‘%’ (Percent)
It means any number of characters in string and also include 0 character.
Here we are writing ContactName LIKE ‘A%’ it means it will fetch all the
contact name starting with A character.We can see result in below diagram.


(2) ‘_’(Underscore)
It represents single character.Here I am trying to show only name those 2nd letter must be ‘n’.
We can see in below diagram.


(3) ‘^’ (Caret)
This is used for negation.Like i don’t want to see those names which are starting with
a to u character.It is very clear from below output.



(4) []
It is used for specify group of characters.Suppose my requirement is i want see those names
only which are starting with c,d,and e character.We can see result what we are trying to say.


That’s It
Enjoy Reading.

2 comments:

Pravesh Singh said...

This is one of the best answer so far, I have read online. Just useful information. Very well presented. I had found another nice post with wonderful explanation on wildcards in sql server over internet.
please check out this link...

http://mindstick.com/Articles/8009b2bd-a5ec-427a-ae50-003a850a7e0e/?SQL%20Wildcards

Thanks

> Blockquote

Shatrughna Kumar said...

Thanks Pravesh

Post a Comment