December 11, 2010 at 3:14 am
I have one computed column Shorthours.
In this computed column i want to display the result in hh.mm
empid FirstIn FirstOut EMPSIN EMPSOut hrworked shorthr
100 08:35:00 18:01:00 08:00:00 18:00:00 9.26 0.74
firstin,firstout is time in and timeout for emp
EMPSIN,EMPSOUt is expected timein and timeout for emp
firstin,firstout,empsin,empsout are in 00:00:00 format so to get the shorthr in time format hh.mm
i am getting the answer 0.74 (answer should be 1.14) using the formula below :
help needed
(case when (0)>((CONVERT([float],datediff(minute,[EmpSIN],[EmpSOut])/(60),(0))+CONVERT([float],(datediff(minute,[EmpSIN],[EmpSOut])%(60))/(100.0),(0)))-(CONVERT([float],datediff(minute,[FirstIn],[FirstOut])/(60),(0))+CONVERT([float],(datediff(minute,[FirstIn],[FirstOut])%(60))/(100.0),(0)))) then (0) else (CONVERT([float],datediff(minute,[EmpSIN],[EmpSOut])/(60),(0))+CONVERT([float],(datediff(minute,[EmpSIN],[EmpSOut])%(60))/(100.0),(0)))-(CONVERT([float],datediff(minute,[FirstIn],[FirstOut])/(60),(0))+CONVERT([float],(datediff(minute,[FirstIn],[FirstOut])%(60))/(100.0),(0))) end)
December 11, 2010 at 6:09 am
Please provide ddl (CREATE TABLE...) script and dml (INSERT INTO...) script which when run will create and populate a table with a few rows of representative data.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
December 11, 2010 at 10:12 am
Employee was expected to work for 10 hrs (1800-0800), but actually worked for 9.26, leaving a shortage of .74 hours. What's the issue here?
(Actually, worked will be 9.566666 (work 9:34: 34/60=.566666666666666666667), so your hrworked calculation is wrong. This means a shortage of .43)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
December 11, 2010 at 1:37 pm
pnasz (12/11/2010)
I have one computed column Shorthours.In this computed column i want to display the result in hh.mm
empid FirstIn FirstOut EMPSIN EMPSOut hrworked shorthr
100 08:35:00 18:01:00 08:00:00 18:00:00 9.26 0.74
firstin,firstout is time in and timeout for emp
EMPSIN,EMPSOUt is expected timein and timeout for emp
firstin,firstout,empsin,empsout are in 00:00:00 format so to get the shorthr in time format hh.mm
i am getting the answer 0.74 (answer should be 1.14) using the formula below :
help needed
(case when (0)>((CONVERT([float],datediff(minute,[EmpSIN],[EmpSOut])/(60),(0))+CONVERT([float],(datediff(minute,[EmpSIN],[EmpSOut])%(60))/(100.0),(0)))-(CONVERT([float],datediff(minute,[FirstIn],[FirstOut])/(60),(0))+CONVERT([float],(datediff(minute,[FirstIn],[FirstOut])%(60))/(100.0),(0)))) then (0) else (CONVERT([float],datediff(minute,[EmpSIN],[EmpSOut])/(60),(0))+CONVERT([float],(datediff(minute,[EmpSIN],[EmpSOut])%(60))/(100.0),(0)))-(CONVERT([float],datediff(minute,[FirstIn],[FirstOut])/(60),(0))+CONVERT([float],(datediff(minute,[FirstIn],[FirstOut])%(60))/(100.0),(0))) end)
What are the datatypes of the time columns?
Also, since you're new to this forum, you should probably set aside a little time and read the article at the first link in my signature line below. It WILL help you get better answers more quickly.
I'll also state that your formula above can be greatly simplified... but we need to know what the datatypes are first AND it would be really helpful if you posted some sample data in the readily consumable format that's outlined in the article I suggested that you study and follow.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 11, 2010 at 1:41 pm
Never mind... someone posted an answer on the cross post at http://www.sqlservercentral.com/Forums/Topic1033293-145-1.aspx even though Gail asked folks to post here.
Moving on.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply