There is a SplitBy Function you can use for this task in Sql Server 2008:
create FUNCTION [dbo].[SplitBy](@String varchar(8000), @Delimiter char(1))
returns @temptable
TABLE (nameIndex int identity(1,1),items varchar(8000))
as
begin
declare @idx int
declare
@slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String
is null return
while @idx!= 0
begin
set @idx =
charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx
- 1)
else
set @slice = @String
if(len(@slice)>0)
insert
into @temptable(Items) values(@slice)
set @String =
right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end
After creating this function, you can easily handle this task like:
declare @string nvarchar(max), @string2 nvarchar(max)
set @string='This is for test';
set @string2='This';
SELECT * into #temp from [SplitBy](@string,' ')
SELECT * into #temp2 from [SplitBy](@string2,' ')
declare @countWordsFirstString int = (select COUNT(*) from #temp)
declare @countWordsResult int = (
select COUNT(*)
from #temp t
join #temp2 t2 on t.items=t2.items
)
print (case when @countWordsResult >= @countWordsFirstString/2 then 'True' else 'False' end)
drop table #temp
drop table #temp2
I hope it helps!
Reference for SplitBy Function: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e676a8e3-ae55-44b6-b36c-fdcd1ef3c70b/sql-to-split-the-string-based-on-the-space-example-split-the-firstname-alone-from-the-complete?forum=transactsql