Finding the average of a data type on a SQL Server

Tags:
Data Types
DateTime
SQL Server
SQL Server DateTime
SQL Server errors
I am trying to figure how to find the average of the data type datetime on my SQL Server. This is my code:
SELECT     CONVERT(varchar, Tanggal_Produksi, 3) AS Tanggal_Produksi, Target, Actual, Balance, CONVERT(varchar, Waktu_Proses_Awal, 8)
                      AS Waktu_Proses_Awal, CONVERT(varchar, Waktu_Proses_Akhir, 8) AS Waktu_Proses_Akhir, CONVERT(varchar,
                      Waktu_Proses_Akhir - Waktu_Proses_Awal, 8) AS Waktu_Proses, Bulan, Tahun
FROM         dbo.Histori_Produksi
This is the error I am getting:
Server: Msg 409, Level 16, State 2, Line 1 The average aggregate operation cannot take a varchar data type as an argument.
What does this mean, and what can I do to fix it?
ASKED: March 5, 2009  8:25 PM
UPDATED: March 5, 2009  8:57 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

I don’t see the AVG operator in your code, in the first place.

The message means that you cannot calculate the average of a varchar type field (and you are converting to varchar some of the columns). If that was possible, you could calculate the average for ‘spring’ and ‘summer’, for example.

But you cannot use the AVG operator on datetime columns either.

Could you please tell us what information you are storing in those datetime fields, and why you need to calculate averages for them ?

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following