Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>declare @SearchItem varchar(1000)='GEO,JCB' </code></pre> <p>declare @Instring varchar(2000)='' select @Instring=@Instring+' when Title like ''%'+items+'%'' then '''+items+'''' from dbo.split(@SearchItem,',') exec(' declare @tbl table(id int,title varchar(200)) ; with CTE as ( select 1 as id, ''Geo Prism GEO 1995 GEO* - ABS #16213899'' as Title union select 2 as id, ''Excavator JCB - ECU P/N: 728/35700'' as Title union select 3 as id, ''Geo Prism GEO 1995 - ABS #16213899'' as Title union select 4 as id, ''JCB Excavator JCB- ECU P/N: 728/35700'' as Title union select 5 as id, '' Geo Prism GEO,GEO 1995 - ABS #16213899 GEO'' as Title union select 6 as id, ''Maruti gear box #ABS 4587'' as Title) </p> <p>insert into @tbl select id,Title from CTE </p> <p>declare @tbl2 table(id int,T int,title varchar(200),Tl varchar(200),CC int) insert into @tbl2 (id,T,title,Tl) select id,T,title,Tl from(select tb.id,sub.T,tb.title ,Tl from (select case '+@Instring +' else ''Other'' END as Tl ,count(*)T from @tbl group by case '+@Instring +' else ''Other'' END)Sub<br> join @tbl tb on tb.Title like ''%''+sub.Tl +''%'' )Sub1</p> <p>declare @Ttle varchar(max) declare @Tl varchar(max) declare @id int declare @i int=0 declare @Nbr int=0 declare Cursr Cursor for select title,id,Tl from @tbl2<br> open Cursr Fetch next from Cursr into @Ttle,@id,@Tl while @@FETCH_STATUS =0 begin while (@i&lt;=len(@Ttle)) begin if charindex(@Tl,@Ttle)!=0 set @Nbr =@Nbr +1 set @Ttle =stuff(@Ttle,charindex(@Tl,@Ttle),len(@Tl),'''') set @i=@i+1 end </p> <pre><code> update @tbl2 set cc=@Nbr where id=@id set @Nbr =0 </code></pre> <p>Fetch next from Cursr into @Ttle,@id,@Tl end </p> <p>select id,T,title,Tl,CC from<br> (select id,T,title,Tl,CC from @tbl2<br> union select id,0 as T,title,'''' as Tl,0 as CC from @tbl where id not in (select id from @tbl2 ))S1 order by T desc,CC desc ' )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload