Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Problem in sql query

my column TotalTime datatype nvarchar(50)=null

Total Time = '15:00' Per Day
Total Time = '15:00'Per Day
Total Time = '15:00' Per Day
Total Time = '15:00'Per Day

count final total = '12:00' (Show This Result For my Query )

but Actual result is '60:00'

Query :-
SQL
SELECT Convert(nvarchar(10), Datepart(HOUR, DATEADD(MINUTE, SUM(DATEDIFF(MINUTE, 00:00;, TotalHour)), 00:00)))+
Convert(nvarchar(10), Datepart(MINUTE, DATEADD(MINUTE, SUM(DATEDIFF(MINUTE,00:00, TotalHour)), 00:00))) as TotalHour
FROM tbl_EmployeeAttendance
where empId='5' and work_type=1
and DateName( month , DateAdd( month , DatePart(Month,convert(datetime,Attendance_Date,103)) , 0 ) - 1 ) ='November' and YEAR(convert(datetime,Attendance_Date,103))= '2014'


Problem :- IF Total time is greater than 24 hour then totaltime calculate start 00:00
but i m count the total time in hour...

forexp:-
total time 1st day 12:00
total time 1st day 13:00
total time 1st day 11:00
total time 1st day 11:00
total time 1st day 12:00

Final Total Time = 59:00


Please Help this problem
Posted
Updated 10-Nov-14 21:32pm
v2
Comments
Tomas Takac 11-Nov-14 3:38am    
Convert your values to numbers representing hours, sum it, calculate remainder when divided by 24, convert to hours.

1 solution

DateTime, Date and Time data types are used to store a point-int-time and not amount of time spent...
As you yourself told you can not record with it more than 24 hours as there is no more than 24 hours in a day!!!
In that sense you original design of the database is wrong! If you want to record the amount of time (hours or minutes) spent use some integer (decimal) data type, so if you have an event that took 36 hours you can write 36 in that column 36 (or 2160 for minutes) and do simple SUM over it!
 
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