Solved

sql 2005 query

Posted on 2007-12-03
3
260 Views
Last Modified: 2010-03-19
HI all,
i have table with
employeeid number
timein datetime
timout datetime

how can i calculate total punched hours. how can i calculate it timeout is null

the sample data i am giving.
empid   storeid      punchin                  punchout
2      1      2007-07-18 18:44:26.897      NULL
95      1      2007-08-22 17:20:04.373      NULL
2      5      2007-08-21 08:00:00.000      2007-08-21 10:00:00.000
2      5      2007-08-21 20:43:17.387      2007-08-22 11:08:40.343
59      7      2007-10-02 15:10:00.000      2007-10-02 18:56:44.973
62      7      2007-09-08 09:15:00.000      2007-09-08 19:30:00.000
62      7      2007-09-17 09:21:00.000      2007-09-17 17:00:00.000
0
Comment
Question by:romeiovasu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:srafi78
ID: 20399436
Select empid, storeid, sum(hours) from
(Select empid, storeid, Case when punchout is null then 0 else
DateDiss(hours , punchin, punchout) end as hours from employee)A
group by empid, storeid
0
 
LVL 8

Accepted Solution

by:
srafi78 earned 250 total points
ID: 20399445
Oops typo
Select empid, storeid, sum(hours) from
(Select empid, storeid, Case when punchout is null then 0 else
DateDiff(hour , punchin, punchout) end as hours from employee)A
group by empid, storeid
0
 
LVL 35

Assisted Solution

by:David Todd
David Todd earned 250 total points
ID: 20399701
Hi,

I'd suggest that instead of taking the datediff by hours that you do it in minutes else get only whole hours. And the amount of hours isn't whole hours as the code snippet shows.

Of course if you want hours you'll have to divide the minutes by 60, but you know that.

Cheers
  David
use tempdb
go
 
declare @StartDate datetime
declare @EndDate datetime
 
select 
	@StartDate = '2007-12-04 11:55:00'
	, @EndDate = '2007-12-04 12:05:00'
 
select 
	datediff( hour, @StartDate, @EndDate ) as hours
	, datediff( minute, @StartDate, @EndDate ) as mins
	

Open in new window

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question