Solved

sql 2005 query

Posted on 2007-12-03
3
244 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
  • 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

840 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