I have a table with such columns:
Table: teeburu Columns: - aidi int identity - bariu varchar(8000)
I want to have a stored procedure for which its input is a string, for example: abc qwe ax xyza Length and number of free places for the user.
And all he does is select all the rows, the bariu column includes all of them: abc , qwe , ax and xyza
Here is what I tried:
I am creating a split function (copied from this page )
create FUNCTION [dbo].[Split](@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
With him, I managed to write something to select all the rows in the bariu column which contain at least one of them: abc , qwe , ax and xyza
with list as( select * from dbo.split(@Param,' ') ) SELECT aidi, bariu FROM teeburu INNER JOIN list ON bariu like '%'+ list.items+ '%' GROUP BY aidi, bariu
But I canβt understand how to do everything instead of at least one of them . My question is: how to do this?
I am using MS SQL SERVER
source share