I’ve hit a bit of a road block with this query I’ve written due to a bookmark lookup which it is performing at the end of its execution. I was wondering if anyone had any suggestions to work around this problem. Query below:
select
isNull(a.groupname, b.groupname) groupname,
isNull(a.gName, b.gName) gName,
isNull(a.sab_count, 0) as sab_count,
isNull(b.prdb_count, 0) as prdb_count
from
( select g.gid, groupname, gName, count(p.pid) as sab_count
from
( select gid, 'g00' + convert(varchar(1), gid) as groupname, gName from groups g where gid < 10
union
select gid, 'g0' + convert(varchar(2), gid) as groupname, gName from groups g where gid > 10 and gid < 100
union
select gid, 'g' + convert(varchar(3), gid) as groupname, gName from groups g where gid > 100 ) g, panelists p
where p.groups like '%' + groupname + '%' and p.validated in (1,2,3,4)
group by g.gid, groupname, gName ) a
FULL OUTER JOIN
( select g.gid, groupname, gName, count(p.prid) as prdb_count
from
( select gid, 'g00' + convert(varchar(1), gid) as groupname, gName from groups g where gid < 10
union
select gid, 'g0' + convert(varchar(2), gid) as groupname, gName from groups g where gid > 10 and gid < 100
union
select gid, 'g' + convert(varchar(3), gid) as groupname, gName from groups g where gid > 100 ) g, prdb p
where p.groups like '%' + groupname + '%'
and p.valid in (0,1)
group by g.gid, groupname, gName ) b on a.gid = b.gid
order by isNull(a.gName, b.gName)
“and p.valid in (0,1)” is where the bookmark is being used. I’ve been trying a few different things based on other posts I’ve read but was wondering if anyone had a fresh idea.
Write this as a case statement
Actually I think u do not even need a case….