Click here to Skip to main content
15,503,143 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
--ID-- DATE-- IN -- OUT--

    -- 10002-- 2015-07-07-- NULL-- 2015-07-07 16:30:10.000--

    --10002-- 2015-07-08-- 2015-07-08 07:23:50.000-- NULL--

    --10003-- 2015-07-08-- 2015-07-08 07:23:50.000-- 2015-07-08 16:23:50.000--


how to calculate the total working hours if a different date and at the date of using sql ?
I already use a method by using datediff, but I do not know how to select if the date is different
Posted
Updated 24-Aug-15 21:47pm
v2

1 solution

If I understand your question correctly, you need to fetch value from two different rows. If that is the case, one way is to use the table twice in the select statement. In other words something like (pseudo code)

SQL
select ...
from tablename a,
     tablename b
where a.id = b.id
and   b.in = (select min(c.in)
              from tablename c
              where c.id = a.id
              and   c.in > a.out)

Depending on the database version, you can possibly do the same with LAG function. Have a look at How to fetch data from the previous or next rows in the resultset[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900