I need to change my SQL below so that for the second condition (and exists...etc) it checks if it exists and if it does exist then the value of a particular field must be 1.
Any ideas how to do this?
(select count(*)
from filteredlead l1
inner join filteredactivitypointer a
on l1.leadid = a.regardingobjectid
where a.activitytypecode in (4201,4401)
and convert(char(10),l1.createdonutc,103) = convert(char(10),getdate()-1,103) and exists (select 1
from filteredlead l
inner join filteredactivitypointer a
on l.leadid = a.regardingobjectid
inner join filteredphonecall p
on a.activityid = p.activityid
where a.activitytypecode = 4210
and p.new_calloutcome in (1,3,4,5,6,7)
and convert(char(10),l.createdonutc,103) = convert(char(10),getdate()-1,103) and l.leadid = l1.leadid))
as 'New Contact Achieved',
Any ideas how to do this?
(select count(*)
from filteredlead l1
inner join filteredactivitypointer a
on l1.leadid = a.regardingobjectid
where a.activitytypecode in (4201,4401)
and convert(char(10),l1.createdonutc,103) = convert(char(10),getdate()-1,103) and exists (select 1
from filteredlead l
inner join filteredactivitypointer a
on l.leadid = a.regardingobjectid
inner join filteredphonecall p
on a.activityid = p.activityid
where a.activitytypecode = 4210
and p.new_calloutcome in (1,3,4,5,6,7)
and convert(char(10),l.createdonutc,103) = convert(char(10),getdate()-1,103) and l.leadid = l1.leadid))
as 'New Contact Achieved',