Finding the average of a data type on a SQL Server
0
Q:
Finding the average of a data type on a SQL Server
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: Mar 5 2009  8:25 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
29855 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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 ?
Last Answered: Mar 5 2009  8:57 PM GMT by Carlosdl   29855 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



0