Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Average Date (Multiple Columns)

Author  Topic 

Weekend
Starting Member

20 Posts

Posted - 2007-08-22 : 02:25:50


Hi

SQL Server 2000
I have four columns of date in a table say Date1, Date2, Date3, Date4 in table Tab_A.
I want to get average date of four columns for each row.
Please advise how?

Thanks
J a w a d

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-22 : 02:59:00
Something similar to this

SELECT Date1, Date2, Date3, Date4, ( SELECT DATEADD(HOUR, AVG(p), 0) FROM
(SELECT DATEDIFF(HOUR, 0, Date1) AS p UNION ALL SELECT DATEDIFF(HOUR, 0, Date2) UNION ALL SELECT DATEDIFF(HOUR, 0, Date3) UNION ALL SELECT DATEDIFF(HOUR, 0, Date4)) AS d)
FROM Tab_A



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Weekend
Starting Member

20 Posts

Posted - 2007-08-22 : 03:19:28
Dear Peso

Thanks you very much.
Your solution work well for me.

Thanks
J a w a d
Go to Top of Page
   

- Advertisement -