Hi All,
Hope you are doing well...I am trying to find the number of days an item was out of stock (denoted by new_status =2) and the number of days the item was disabled (denoted by new_status >2) .. New_status =1 denotes that the item is available)... the number of days can be denoted as a decimal too(like 2.2 days ,3.4 days).. The new_status denotes the current status and the old_Status denotes the prior status... I have also provided the output table too...Can you please help here!..
create table ##temp1
(itemid varchar(30),
timett datetime2,
old_status int,
new_status int)
insert into ##temp1 values
('4213','2019-06-03 11:56:41.360','1','2'),
('4213','2019-06-05 11:56:41.360','2','3'),
('4213','2019-06-07 13:56:41.360','3','1'),
('5214','2019-06-01 09:56:41.360','3','1'),
('5214','2019-06-02 09:56:41.360','1','2'),
('5214','2019-06-05 09:56:41.360','2','1'),
('7896','2019-06-02 06:26:42.717','2','1'),
('7896','2019-06-02 06:56:42.717','1','7'),
('7896','2019-06-02 08:56:42.717','7','2'),
('7896','2019-06-02 09:20:42.717','2','1'),
('7896','2019-06-03 09:20:42.717','1','3'),
('7896','2019-06-03 09:50:42.717','3','2');
--Output
create table ##output
(itemid varchar(20),
outofstatusnoofdays float,
disablednoofdays float)
insert into ##output values
('4213','2','2.08'),
('5214','3','0'),
('7896','0.02','0.1')
Thanks,
Arun