AVG(DateDiff) in one line?

  • I am trying to pull a report with average down time and I getting the error message "Msg 195, Level 15, State 10, Line 4

    'AVG' is not a recognized built-in function name." when I try to run the below query. How can I rephrase the AVG(DateDiff) line to calculate this for me? Also, what would this be called so I can do some additional learning on the topic?

    SELECT

    TT.PartNumber

    ,AVG (TT.TimeToRepair) as [Avg Time to Repair (Hours)]

    ,AVG(DateDiff (hour,TT.TimeDateReported,TT.DateClosed) as [Turnaround Time(Hours)])

    FROM dbo.vt_TroubleTicket TT

    WHERE TT.Closed = '-1'

    and TT.DateClosed between '1/1/2013' and '1/1/2014'

    and (TT.PartNumber = '12345')

    GROUP BY TT.PartNumber

  • jennigirl (11/10/2014)


    I am trying to pull a report with average down time and I getting the error message "Msg 195, Level 15, State 10, Line 4

    'AVG' is not a recognized built-in function name." when I try to run the below query. How can I rephrase the AVG(DateDiff) line to calculate this for me? Also, what would this be called so I can do some additional learning on the topic?

    SELECT

    TT.PartNumber

    ,AVG (TT.TimeToRepair) as [Avg Time to Repair (Hours)]

    ,AVG(DateDiff (hour,TT.TimeDateReported,TT.DateClosed) as [Turnaround Time(Hours)])

    FROM dbo.vt_TroubleTicket TT

    WHERE TT.Closed = '-1'

    and TT.DateClosed between '1/1/2013' and '1/1/2014'

    and (TT.PartNumber = '12345')

    GROUP BY TT.PartNumber

    You need to change your closing parenthesis.

    SELECT

    TT.PartNumber

    ,AVG (TT.TimeToRepair) as [Avg Time to Repair (Hours)]

    ,AVG(DateDiff (hour,TT.TimeDateReported,TT.DateClosed)) as [Turnaround Time(Hours)]

    FROM dbo.vt_TroubleTicket TT

    WHERE TT.Closed = '-1'

    and TT.DateClosed between '1/1/2013' and '1/1/2014'

    and (TT.PartNumber = '12345')

    GROUP BY TT.PartNumber

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • That was embarrassingly simple. Thank you for your time!

  • Sometimes we miss the little details and just need a different point of view.

    Glad I could help.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply