sql match strings by substrings code example
Example 1: check if string contains substring sql
Declare @mainString nvarchar(100)='Amit Kumar Yadav'
---Check here @mainString contains Amit or not, if it contains then retrun greater than 0 then print Find otherwise Not Find
if CHARINDEX('Amit',@mainString) > 0
begin
select 'Find' As Result
end
else
select 'Not Find' As Result
Example 2: sql where part of string match
select * from docs where DOC_NAME like '%virus%spyware%'
-- OR
select * from docs where DOC_NAME like '%virus%' or DOC_NAME like '%spyware%'