I have a table with a ‘call open date’ column (actual_log_date) which I convert, using
convert(char(10), actual_log_date, 103) 'Call Logged'
to show calls logged on 01/02/2012 for example.
There is also a close time column (close_time) for which I run the same convert,
convert(char(10), close_time, 103) 'Call Closed'
to show calls closed on 12/02/2012.
Now, I need to produce a script to get the average number of days calls have been open. I can run
(select datediff(dd, c.actual_log_date, c.close_time)) as 'Days Open'
to create the column which shows the call was open for 12 days or whatever, but now need to count all the records and obtain the average sum at the end of the results, which is where I am stuck!
I forgot to say I can’t create a temp table as I only have read only rights.
Sorry, I’m new here so not sure on the protocol but here is the script if it’s easier to answer seeing what I’m working with;
select
convert(char(10),actual_log_date,103) 'Call Logged',
call_number 'Call #',
short_problem 'Issue Description',
Customer = (select surname + ', ' + first_name from i.ar_user_attributes where ref = user_ref ),
Officer = (select surname + ', ' + first_name from i.su_help_centre where ref = resolve_officer),
Department = (select name from i.su_support_group where ref = resolve_group),
convert(char(10),close_time,103) 'Closed',
(select datediff(hh,c.actual_log_date,c.close_time)) as 'Hours Open',
(select datediff(dd,c.actual_log_date,c.close_time)) as 'Days Open'
from
i.cl_call_logging c
where
c.resolve_time between
convert(datetime,convert(varchar,month(dateadd(m,-1,getdate()))) + '/01/' + convert(varchar,year(dateadd(m,-1,getdate())))) and
convert(datetime,convert(varchar,month(getdate())) + '/01/' + convert(varchar,year(getdate())))
and c.resolve_group in ('48', '60')
Thanks again!
You can use a with query, like this:
Using your full script, try this: