Search This Blog

Thursday, 15 November 2012

Read wild card character as Charater

Requirement :- Let's have a sample data as below and you need to search the data started with %, _ in your table
Id    
Item
1    _Computer
2
    
%Computer
3   
%Desk
4  
%pen
_
pen
Create table #test (ID int , Item varchar(50))
insert into #test values (1,'_Computer')
insert into #test values (2,'%Computer')
insert into #test values (3,'%Desk')
insert into #test values (4,'%Pen')
insert into #test values (5,'_Pen')

Solution :- Just put your wild card character in open and closed square brackets
Example :-
Select * from #test where Item like '[%]%'