IanWaterman
Programmer
I have to come up with a query to count calls in a month. I also have to count calls which span month ends.
So far I have 4 simply queries unioned together to give me Calls opened, calls closed, calls carried forward, ie opened in month but closed in subsequent month and calls brought forward, opened in prior month and closed in subsequent month.
The brought forward anc carried forward are failing when a call spans more than a month. For example I have 50 calls opened at end of Feb but were not closed until April.
So my data looks like
Feb Carried forward = 232
March Brought forward = 182
March carried forward = 189
April Brought forward = 239
I can only count data based on Accepted dates and Cleared dates, when a call is uncleared ie still open the date is set as 1900/01/01.
A further complication is that calls can remain open for several months, How do I add counts in the intervening months to increment BF and CF figures by those calls.
BF Query
select callno,
case when dcleared = {ts '1900-01-01 00:00:00'} then getdate() else dcleared end post_date,
1 as Brought_forward,
0 as Opened,
0 as Closed,
0 as Carried_forward
from calldetails
where ccode = 'LBLEW'
AND daccepted >= dateadd(yy, -1, DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0))
And daccepted < DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0)-1
and (MONTH(daccepted) < MONTH(dcleared) or dcleared = {ts '1900-01-01 00:00:00'})
CF query
select callno, daccepted post_date,
0 as Brought_forward,
0 as Opened,
0 as Closed,
1 as Carried_forward
from calldetails
where ccode = 'LBLEW'
AND daccepted >= dateadd(yy, -1, DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0))
And daccepted < DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0)-1
and (MONTH(daccepted) < MONTH(dcleared) or dcleared = {ts '1900-01-01 00:00:00'})
I appreciate I will have to improve my test for calls spanning a year end too.
The report is a rolling 12 months to be run on the first day of a month. This will need to be changed too to cater for calls still open in 12 months time, system was only installed in Feb this year, so not an issue yet.
Thanks
Ian
So far I have 4 simply queries unioned together to give me Calls opened, calls closed, calls carried forward, ie opened in month but closed in subsequent month and calls brought forward, opened in prior month and closed in subsequent month.
The brought forward anc carried forward are failing when a call spans more than a month. For example I have 50 calls opened at end of Feb but were not closed until April.
So my data looks like
Feb Carried forward = 232
March Brought forward = 182
March carried forward = 189
April Brought forward = 239
I can only count data based on Accepted dates and Cleared dates, when a call is uncleared ie still open the date is set as 1900/01/01.
A further complication is that calls can remain open for several months, How do I add counts in the intervening months to increment BF and CF figures by those calls.
BF Query
select callno,
case when dcleared = {ts '1900-01-01 00:00:00'} then getdate() else dcleared end post_date,
1 as Brought_forward,
0 as Opened,
0 as Closed,
0 as Carried_forward
from calldetails
where ccode = 'LBLEW'
AND daccepted >= dateadd(yy, -1, DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0))
And daccepted < DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0)-1
and (MONTH(daccepted) < MONTH(dcleared) or dcleared = {ts '1900-01-01 00:00:00'})
CF query
select callno, daccepted post_date,
0 as Brought_forward,
0 as Opened,
0 as Closed,
1 as Carried_forward
from calldetails
where ccode = 'LBLEW'
AND daccepted >= dateadd(yy, -1, DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0))
And daccepted < DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0)-1
and (MONTH(daccepted) < MONTH(dcleared) or dcleared = {ts '1900-01-01 00:00:00'})
I appreciate I will have to improve my test for calls spanning a year end too.
The report is a rolling 12 months to be run on the first day of a month. This will need to be changed too to cater for calls still open in 12 months time, system was only installed in Feb this year, so not an issue yet.
Thanks
Ian