---StartDate ------------ StopDate --
______________________________________________
01/05/2005 7:30 AM -------- 03/05/2005 10:00 AM
13/05/2005 2:30 PM -------- 01/08/2005 8:00 PM
_____________________________________________
How do I find out the avg time difference between StopDate and StartDate? I triedAVG(StopDate - StartDate ),but it's giving me the following error message.
"The average aggregate operation cannot take a smalldatetime data type as an argument."
Thanks for any reply.
polash26 wrote: I triedAVG(StopDate - StartDate ),but it's giving me error message. Thanks for any reply.
The key to solving any programming problem is to read the error messageand understand what it is telling you. When you seek help fromother programmers, the very first thing you are going to be asked is"what exactly does the error message say?"
In your case, I am assuming you are receiving this error message:
The average aggregate operation cannot take a datetime data type as an argument.Try using the DATEDIFF function, which will return you an integer datatype. You CAN use the AVG function on an integer data type.
This, for example, will give you the average number of hours between the myDateTime column and the current system date:
SELECT AVG(DATEDIFF(hh,myDateTime, GETDATE())) FROM test
No comments:
Post a Comment