Monday, August 31, 2020

HOW TO USE LIKE OPERATOR IN SQL SERVER

 LIKE Operator: The LIKE operator is used to find a specified pattern to filter rows or records from a table.It is most widely used into the WHERE clause with SELECT, DELETE and UPDATE sql statements.

The two wildcards are often used with LIKE operator. These are as below:

a) % or Percent Sign

b) _ or Underscore Sign

a) % or Percent Sign: It represents 0, 1, or multiple characters.

b) _ or Underscore Sign: It represents a single character. 

The syntax of  LIKE operator is as follows:

SELECT * FROM TABLE WHERE COLUMN LIKE '%R%'

So, here we have a Employee table with list of records.


Now, we will use a LIKE operator to filter records from Employee table.

1. %SACH% : It fetches all the records from an employee table that have SACH character in any position. Please see the screenshot as belows:



2. R% : It fetches all the records that start with R character from an employee table. Please see the below screenshots.


3. %R : It fetches all the records that ends with R character from an employee table. Please see the below screenshots.


4. _R% : It fetches all the records from an employee table that have R character is in second position. Please see the below screenshots.


5. R_% : It fetches all the records from an employee table that have R character is in first position. Please see the below screenshots.


6. R%H : It fetches all the records from an employee table that have R character is in first position and H character is in last position. Please see the below screenshots.



                - - - - - - Cheers, Happy to Help! - - - - - - 


No comments:

Post a Comment

DIFFERENCE BETWEEN CHAR AND VARCHAR IN SQL SERVER

CHAR:  The  CHAR datatype is a fixed length data type in sql server. It is used to store fixed length type of string data or character strin...