I have a some scan times from a warehouse job , the table shows where the job was parked for breaks / overnight , I cant think of a logical way to just calculate the time between the breaks . The total time spent is 54 minutes but the actual pick time is only 9mins , As always any pointer greatly appreciated
Create table #packpark
( Shipment bigint,
Shipmentid Nvarchar (20),
CreatedUser Nvarchar (20),
TableName Nvarchar (50),
CreatedDate Datetime ,
AuditCode Nvarchar (50),
QtyPicked decimal (13,2),
SystemType Nvarchar (20)
)
INSERT INTO #packpark
VALUES
('849975', '', 'Jon', 'bdt_PickedItems', '2023-01-26 10:09:00.723', 'Picking Started', '0.00000', 'S'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:09:28.833', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:09:29.380', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:09:29.910', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:09:43.147', '', '1.00000', 'N'),
('849975', '', 'Jon', 'bdt_PickedItems', '2023-01-26 10:09:48.630', 'Picking Parked', '0.00000', 'P'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:15:11.587', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:15:12.290', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:15:13.257', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:15:21.570', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:15:37.710', '', '1.00000', 'N'),
('849975', '', 'Jon', 'bdt_PickedItems', '2023-01-26 10:15:43.070', 'Picking Parked', '0.00000', 'P'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:26:23.343', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:26:57.907', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:27:12.780', '', '1.00000', 'N'),
('849975', 'SH00216747', 'Jon', 'Picking', '2023-01-26 10:27:13.657', '', '1.00000', 'N'),
('849975', '', 'Jon', 'bdt_PickedItems', '2023-01-26 10:50:09.320', 'Picking Parked', '0.00000', 'P')
Select
Shipment
,ShipmentId
,CreatedUser
,Tablename
,CreatedDate
,CONVERT(VARCHAR(15), CONVERT(TIME , CreatedDate - LAG(CreatedDate) OVER (ORDER BY CreatedDate)))as time_hhmm
,AuditCode
,QtyPicked
,SystemType
from
#packpark
drop table #packpark
Results look like this
[Results](https://drive.google.com/file/d/1pgowz-nVs3bEqGPCkClJjvQ5xKRXeg8W/view)