We generally use a UDF to split a string into tabular data and can use like command for the same.
declare @searchStr nvarchar(100)
set @searchStr = 'brown fox'
selecT T.* from test T, dbo.fnc_SplitSTring(@searchStr,' ')
where T.name like '%' + token + '%'
CREATE FUNCTION [dbo].[fnc_SplitString]
(
@InString varchar(8000),
@Delim char(1)
)
RETURNS @Return table
(
Position int identity,
Token varchar(100) -- Maximum token size is 100 chars...
)
As
BEGIN
Declare @CR varchar(1),
@LF varchar(1)
Set @CR = char(10)
Set @LF = char(13)
--
If @InString is null return
--
Declare @Pos int
Declare @Pattern char(3)
Set @Pattern = '%' + @Delim + '%'
--
Declare @Token varchar(30)
SELECT @InString = @InString + @Delim -- add trailing delimiter
SELECT @Pos = PATINDEX(@Pattern, @InString)
WHILE (@Pos <> 0) BEGIN
SELECT @Token = ltrim(rtrim(SUBSTRING(@InString, 1, @Pos - 1)))
Select @Token = replace(@Token, @CR, '')
Select @Token = replace(@Token, @LF, '')
Insert @Return Values (@Token)
SELECT @InString = STUFF(@InString, 1, PATINDEX(@Pattern, @InString),'')
SELECT @Pos = PATINDEX(@Pattern, @InString)
END
--
return
--
END