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
 calculation within a column

Author  Topic 

NhanLe
Starting Member

3 Posts

Posted - 2008-10-27 : 07:23:05
Date happening duration
11/11/2008 online 8:00
11/11/2008 offline1 1:00
11/11/2008 offline2 2:10
11/11/2008 offline1 0:20
12/11/2008 online 16:00
12/11/2008 offline2 0:30

How can I calculate for every day the duration of the online time?
online - (sum(offline1)+sum(offline2)

Result should be a resume for every day:
date RealOnline
11/11/2008 4:30
12/11/2008 15:30

Looking forward for your help

Thanks
Nhan

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-27 : 07:28:54
[code]SELECT DATEADD(dd,DATEDIFF(dd,0,Date),0),
SUM(CASE WHEN happening ='online' THEN duration ELSE 0 END)-(SUM(CASE WHEN happening ='offline1' THEN duration ELSE 0 END)+SUM(CASE WHEN happening ='offline2' THEN duration ELSE 0 END))
FROM YourTable
GROUP BY DATEADD(dd,DATEDIFF(dd,0,Date),0)[/code]
Go to Top of Page

NhanLe
Starting Member

3 Posts

Posted - 2008-10-27 : 07:51:19
dear visakh16,

Thank you for the extremely fast response, looks very neat.
Yet I've mistaken in the forum. I need the code for access 2003.

U're great
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-27 : 07:59:25
quote:
Originally posted by NhanLe

dear visakh16,

Thank you for the extremely fast response, looks very neat.
Yet I've mistaken in the forum. I need the code for access 2003.

U're great



then please post this in access forum.
Go to Top of Page
   

- Advertisement -