Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7570565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:27:28+00:00 2026-05-30T15:27:28+00:00

I have a table with a ‘call open date’ column (actual_log_date) which I convert,

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:27:29+00:00Added an answer on May 30, 2026 at 3:27 pm

    You can use a with query, like this:

    insert into @temp (CallOpen, CallClosed)
    values
    ('2012-01-02', '2012-02-12'),
    ('2012-01-05', '2012-02-12'),
    ('2012-01-07', '2012-02-05'),
    ('2012-01-14', '2012-02-03'),
    ('2012-02-10', '2012-03-15')
    
    ;with T1 as 
    (
    select
        CallOpen,
        CallClosed,
        DATEDIFF(dd, callopen, callclosed) as DaysOpen
    from @temp
    )
    
    select AVG(daysopen) from T1
    

    Using your full script, try this:

    ;with T1 as
    (
    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 @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')
    )
    
    select AVG([Days Open]) from T1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table defined with FlexiGrid. Call to all variables is ok. One column
I have table which has a class data and it has table rows inside
i have table contain two column id and word . word column may contain
I have table in sqlalchemy 0.4 that with types.DateTime column: Column(dfield, types.DateTime, index=True) I
I have table which will only contain information about files, so, as the file
I have table named Table X which contains some names and their corresponding age,
I have table that has date field. When I run a query, I see
I have table view which is showing list of files to download. When I
I have table named A with column B defined int not null Primary Key
I have table with data about tasks like Id, Name, Date, WorkerId, VehicleId (and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.