All Type Coding

Search Here

Like operator in sql server.


LIKE OPERATOR:
LIKE operator is used in a WHERE clause to search for a specified pattern in a column  LIKE operator is to compare a value to similar values using wildcard operators. There are two wildcards used in conjunction with the LIKE operator:
1-  The percent sign (%)
2-   The underscore (_)

Syntax:
                Select * from table_name where cloumn_name LIKE  'AAAA%'
             OR
            Select * from table_name where cloumn_name LIKE  '%AAAA%'
             OR
            Select * from table_name where cloumn_name LIKE  '_AAAA'
             OR
            Select * from table_name where cloumn_name LIKE  'AAAA_'
             OR
            Select * from table_name where cloumn_name LIKE  '_AAAA_'
            OR
            Select * from table_name where cloumn_name LIKE  '%AAAA' 

We can combine n  number of conditions using AND or OR operators. Here, AAAA could be any numeric or string value.
Let us take a real example, consider the Employee1 table having the following records:


















Following is an example, which would display all the records from Employee1 table.where Name start with A












Following is an example, which would display all the records from Employee1 table where Name start with BB















Following is an example, which would display all the records from Employee1 table where Name start with Ra














We  can use like operator  with other operator like NOT 




















No comments :

Post a Comment