Help to find in sequence issue in groups records
Hi, Every group_cost has different sequence of PP_Seq but it should not be any gap in the sequence of any group_cost rcords. It should always be increment by 1. I want to see any record/row of any group_cost if it has any issue in pp_seq and not increment by 1. I want to see when the issue of sequence is started then it will be corrected with other next rows.
Create table #Cost (group_cost char(10), PP_Seq int, date1 datetime, ST char(2))
insert into #cost (‘T1′,5,’2023-01-01′,’A’)
insert into #cost (‘T1′,6,’2023-02-01′,’A’)
insert into #cost (‘T1′,7,’2023-03-01′,’A’)
insert into #cost (‘T2′,12,’2023-01-01′,’A’)
insert into #cost (‘T2′,14,’2023-02-01′,’B’) — This pp_seq is not increment by 1. Should be in output
insert into #cost (‘T2′,15,’2023-03-01′,’A’)
insert into #cost (‘T3′,25,’2023-01-02′,’A’)
insert into #cost (‘T3′,26,’2023-02-01′,’A’)
insert into #cost (‘T3′,27,’2023-03-05′,’A’)
insert into #cost (‘T5′,65,’2023-01-01′,’A’)
insert into #cost (‘T5′,66,’2023-02-06′,’A’)
insert into #cost (‘T5′,67,’2023-03-04′,’W’)
insert into #cost (‘T5′,69,’2023-04-01′,’A’) — This pp_seq is not increment by 1. Should be in output
–Expected result
group_cost PP_Seq date1 ST Comments
T2 14 2023-02-01 B PP_Seq is not in seq. Also check next rows to correct.
T5 69 2023-04-01 A PP_Seq is not in seq. Also check next rows to correct.
Hi, Every group_cost has different sequence of PP_Seq but it should not be any gap in the sequence of any group_cost rcords. It should always be increment by 1. I want to see any record/row of any group_cost if it has any issue in pp_seq and not increment by 1. I want to see when the issue of sequence is started then it will be corrected with other next rows. Create table #Cost (group_cost char(10), PP_Seq int, date1 datetime, ST char(2))insert into #cost (‘T1′,5,’2023-01-01′,’A’)insert into #cost (‘T1′,6,’2023-02-01′,’A’)insert into #cost (‘T1′,7,’2023-03-01′,’A’) insert into #cost (‘T2′,12,’2023-01-01′,’A’)insert into #cost (‘T2′,14,’2023-02-01′,’B’) — This pp_seq is not increment by 1. Should be in output insert into #cost (‘T2′,15,’2023-03-01′,’A’) insert into #cost (‘T3′,25,’2023-01-02′,’A’)insert into #cost (‘T3′,26,’2023-02-01′,’A’)insert into #cost (‘T3′,27,’2023-03-05′,’A’) insert into #cost (‘T5′,65,’2023-01-01′,’A’)insert into #cost (‘T5′,66,’2023-02-06′,’A’)insert into #cost (‘T5′,67,’2023-03-04′,’W’)insert into #cost (‘T5′,69,’2023-04-01′,’A’) — This pp_seq is not increment by 1. Should be in output –Expected resultgroup_cost PP_Seq date1 ST CommentsT2 14 2023-02-01 B PP_Seq is not in seq. Also check next rows to correct. T5 69 2023-04-01 A PP_Seq is not in seq. Also check next rows to correct. Read More