Hello all,
I am trying to extract minimum maximum time from terminal ID until it changes the business according to our flag.
1 = means changing business
0 = same business
and I need to merge into one record from multiple records in multiple records in the sequence of time.
as per below codes
sample data
Expected result:
any help would be much appreciated!
I am trying to extract minimum maximum time from terminal ID until it changes the business according to our flag.
1 = means changing business
0 = same business
and I need to merge into one record from multiple records in multiple records in the sequence of time.
as per below codes
sample data
Code:
DECLARE @Test TABLE (TERMINAL_ID int,
TERMINAL_NAME varchar(200),
START_DATE datetime,
END_DATE datetime,
CHANGE_FLAG bit)
INSERT INTO @Test VALUES(1128565, 'JAPANPOST BANK(705910) OKINAWA JP','20160501','20161231',1)
INSERT INTO @Test VALUES(1128565, 'JAPANPOST BANK(003500) TOKYO JP 1','20170101','20170531',0)
INSERT INTO @Test VALUES(1128565, 'JAPANPOST BANK(003500) TOKYO JP 2','20170601','20170630',0)
INSERT INTO @Test VALUES(1128565, 'JAPAN RAMEN','20170701','20170831',1)
INSERT INTO @Test VALUES(1128565, 'JAPAN RAMEN AU','20170901','20170930',0)
INSERT INTO @Test VALUES(1128565, 'JAPAN RAMEN AUS','20171001','99991231',0)
INSERT INTO @Test VALUES(4184558, 'POST Diamond Creek F VicAU','20160501','20161031',1)
INSERT INTO @Test VALUES(4184558, 'BRIDGE CLINIC MURRAY BRIDGESA AU','20170501','20170630',1)
INSERT INTO @Test VALUES(4184558, 'BRIDGE CLINIC MURRAY BRIDGESA AU','20170701','20171231',0)
INSERT INTO @Test VALUES(4184558, 'BRIDGE CLINIC MURRAY BRIDGESA AU','20180101','99991231',0)
Expected result:
Code:
1128565 JAPANPOST BANK(705910) OKINAWA JP 2016-05-01 00:00:00.000 2017-06-30 00:00:00.000 1
1128565 JAPAN RAMEN 2017-07-01 00:00:00.000 9999-12-31 00:00:00.000 1
4184558 POST Diamond Creek F VicAU 2016-05-01 00:00:00.000 2016-10-31 00:00:00.000 1
4184558 BRIDGE CLINIC MURRAY BRIDGESA AU 2017-05-01 00:00:00.000 9999-12-31 00:00:00.000 1
any help would be much appreciated!