How to use wildcard character in a SQL query


What is the wildcard character in a SQL query?


SQL wildcards can be used when searching for data in a database. SQL wildcards are used with the LIKE operator, which acts as a comparison when searching the database. We will use the '%' and '_' wildcards in SQL Server. Wildcards are used in SQL to match a string pattern

 Percent sign (%)

   select * from Employee where name like 'b%'
   It will show record of name which start with b


   select * from Employee where name like '%b'
    It will show record of name which end with b

  
   select * from Employee where name like '%st%' --
   It will Pick up the record from middel ,last or first


   Dash(_):

  
   select * from Employee where user_id like '_eha'
   It will show record of user_id which end with last three matching characters
  
   select * from Employee where user_id like '_e_a'
  
   select * from Employee where user_id like '_e_a'
  
   select * from Employee where user_id like '[lnr]%'
  
   select * from Employee where user_id like '[!lnr]%' --not like
  
   select * from Employee where user_id like '[a-n]%'


1 Comments

  1. awesome dude this one is cleared my doubt...keep it up...send me new updates

    ReplyDelete

Post a Comment

Post a Comment

Previous Post Next Post