questions tagged with [tag], but not by any of [tag list]

0

Please login or register to vote for this query.

(click on this box to dismiss)

Android Enthusiasts Meta

Q&A about the site for enthusiasts and power users of the Android operating system

declare @tag nvarchar(35) = ##tag:string##;
declare @list nvarchar(max) = ##list:string##;

declare @includeTags bit = iif(##includeTags:string?yes## = 'yes', 1, 0);

declare @tagsToExclude table ( 
  tag nvarchar(35) COLLATE SQL_Latin1_General_CP1_CS_AS 
);

declare @pos int = 0;
declare @nxt int = 0;
declare @len int = len(@list);

while @pos <= @len
  begin
  
    set @nxt = charindex(',', @list, @pos);
    set @nxt = iif(@nxt = 0, @len + 1, @nxt);
  
    insert into @tagsToExclude 
    values (
      '%<' + trim ( substring( @list, @pos, @nxt - @pos ) ) + '>%'
    );
      
    set @pos += @nxt - @pos + 1;
  
  end;
  
select row_number() over (order by Tags) as Row, * from
(
select distinct
  Id as [Post Link],
  Tags
from
  Posts
where
  charindex('<' + @tag + '>', Tags) > 0
  and
  PostTypeId = 1
  and
  (
    @includeTags = 1 and exists(select 1 from @tagsToExclude where Tags like tag)
    or
    @includeTags = 0 and not exists(select 1 from @tagsToExclude where Tags like tag)
  ) 
) dist

--select * from @tagsToExclude

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results