sql - Removing While Loop in String Search Query -


i have query takes 1 record #itemtemp, , locates entries reportcsharp match, inserting matches #link_table. @ present, query runs in 7.5 min, appears slow iterating on 1458 records in #itemtemp table.

declare      @num    int ,   @path   varchar(100) ,   @output varchar(100) ,   @max    int  set @num = 1  set @max = (select max(num) #itemtemp)  while @num < @max begin      set @path = (select path #itemtemp num = @num)      insert #link_table     select          itemid     ,   path     ,   @path     reportcsharp     script '%"' + @path + '"%'       set @num += 1 end 

how can remove while loop , replace more set based operations?

insert #link_table     select rcs.itemid,            rcs.path,            it.path         reportcsharp rcs             inner join #itemtemp                 on rcs.script '%' + it.path + '%'; 

Popular posts from this blog