I need to do a record count based upon i) fields being equal to a given value, or ii) the count of another query being > 0.
Here is my SQL at the moment :
This is the bit where I am checking for a valid a.activitytypecode and a valid l.createdonutc (date) :
(select count(*)
from filteredlead l
inner join filteredactivitypointer a
on l.leadid = a.regardingobjectid
where a.activitytypecode in (4201,4401)
and convert(char(10),l.createdonutc,103) = convert(char(10),getdate(),103)
or
(select count(a.activityid)
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(),103)) < 0
And this the part where I am checking that another count < 0. Can anybody tell me what I am doing wrong here, I know my syntax isn't quite right but I'm not sure how to correct it.
Here is my SQL at the moment :
This is the bit where I am checking for a valid a.activitytypecode and a valid l.createdonutc (date) :
(select count(*)
from filteredlead l
inner join filteredactivitypointer a
on l.leadid = a.regardingobjectid
where a.activitytypecode in (4201,4401)
and convert(char(10),l.createdonutc,103) = convert(char(10),getdate(),103)
or
(select count(a.activityid)
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(),103)) < 0
And this the part where I am checking that another count < 0. Can anybody tell me what I am doing wrong here, I know my syntax isn't quite right but I'm not sure how to correct it.