Hi All,
I have asked this question before, but some gentleman asked me to provide data as in below,
I couldn't edit previous question rising this topic again.
I have 2 tables with same headers, I need to Union them first.
then with Union output I would like to forward fill null Locations to last not null value.
also, I would like to extract only last 3 days data from it.
I have attached image below for more clarification and table data also attached. please check.
I have latest SSMS installed
Many thanks in advance for your help
Table 1:
CREATE TABLE mytable(
Date DATE NOT NULL PRIMARY KEY
,Name VARCHAR(6) NOT NULL
,qty INTEGER NOT NULL
,Location VARCHAR(8)
);
INSERT INTO mytable(Date,Name,qty,Location) VALUES ('01/01/2022','Apple',2,'1st row');
INSERT INTO mytable(Date,Name,qty,Location) VALUES ('01/01/2022','Orange',10,'2nd row');
INSERT INTO mytable(Date,Name,qty,Location) VALUES ('02/01/2022','Apple',5,NULL);
INSERT INTO mytable(Date,Name,qty,Location) VALUES ('02/01/2022','Kiwi',1,'10th row');
Table 2:
CREATE TABLE mytable2(
Date DATE NOT NULL PRIMARY KEY
,Name VARCHAR(6) NOT NULL
,qty INTEGER NOT NULL
,Location VARCHAR(8)
);
INSERT INTO mytable2(Date,Name,qty,Location) VALUES ('03/01/2022','Orange',9,NULL);
INSERT INTO mytable2(Date,Name,qty,Location) VALUES ('04/01/2022','Apple',10,'3rd row');
INSERT INTO mytable2(Date,Name,qty,Location) VALUES ('05/01/2022','Kiwi',4,NULL);
INSERT INTO mytable2(Date,Name,qty,Location) VALUES ('05/01/2022','Apple',2,'5th row');
INSERT INTO mytable2(Date,Name,qty,Location) VALUES ('06/01/2022','Apple',5,NULL);