OR condition in Like operator of SQL

Rajnilari2015
Posted by Rajnilari2015 under Sql Server category on | Points: 40 | Views : 1148
Let's say we have a table as under

Record  
Othelo
Macbeth
IPL
Performance Tuning


The expected output should be

Record  
Othelo
Macbeth


Query
------


DECLARE @t TABLE (Record VARCHAR(500))
INSERT INTO @t
SELECT 'Othelo' UNION ALL
SELECT 'Macbeth' UNION ALL
SELECT 'IPL' UNION ALL
SELECT 'Performance Tuning'



SELECT * 
FROM @t
WHERE Record LIKE '%h%'
OR Record LIKE '%b%'


So here we have used LIKE and OR together to accomplish the result.

Comments or Responses

Login to post response