How to split the total time with condition
Using SQL Server.
Table1
ID TotalTime
001 12:00:00
002 11:00:00
003 09:00:00
004 08:00:00
005 14:00:00
....
....,
TotalTime Datatype is nvarchar
I need to split the total time column in to 3 columns like the below condition
First 8 Hours should display in First column
After 8 Hours the next 2 Hours should display in Second column
After 10 Hours the remaining hours should display in third column
Expected Output
ID TotalTime Column1 Column2 Column3
001 12:00:00 08:00:00 02:00:00 02:00:00
002 11:00:00 08:00:00 02:00:00 01:00:00
003 09:00:00 08:00:00 01:00:00
004 08:00:00 08:00:00
005 14:00:00 08:00:00 02:00:00 04:00:00
..开发者_StackOverflow社区..
....,
How to make a query for the above condition.
Need Query Help.
You could use a case
to split up the time:
select ID
, case when totaltime > 8 then 8
else totaltime end
, case when totaltime > 10 then 2
when totaltime > 8 then totaltime - 8
else 0 end
, case when totaltime > 10 then totaltime - 10
else 0 end
from YourTable
精彩评论