D
DiDi
I have plant-fertilizer-season Table, where applied fertilizers to
plant is different for seasons, fert1 is main fertilizer used, fert2,
fert3, fert4 would be for the secondary, auxiliary used, below is a few
records for reference:
Tab_MPlant:
ID Plant fert1 fert2 fert3 fert4 Season
1 P1 S1 S3 S2 F
2 P1 S4 S2 S1 S3 S
3 P2 S1 S3 S4 F
4 P2 S2 S1 S3 S4 S
By introducing a fert_ID and using Make Table queries and Append
queries I can finally come up the following Table:
Tab_SPlant:
ID Plant fert Fert_ID Season
1 P1 S1 1 F
1 P1 S3 2 F
1 P1 S2 3 F
2 P1 S4 1 S
2 P1 S2 2 S
2 P1 S1 3 S
2 P1 S3 4 S
3 P2 S1 1 F
3 P2 S3 2 F
3 P2 S4 3 F
4 P2 S2 1 S
4 P2 S1 2 S
4 P2 S3 3 S
4 P2 S4 4 S
However, when the plant inventory grows, a manually manipulate queries
become very cumbersome. How to make the follow process becomes
automation within Access?
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert1 AS Fert, 1 AS
fert_ID, Tab_Mplant.season INTO Tab_f1
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert1) Is Not Null));
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert2 AS Fert, 2 AS
fert_ID, Tab_Mplant.season INTO Tab_f2
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert2) Is Not Null));
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert3 AS Fert, 3 AS
fert_ID, Tab_Mplant.season INTO Tab_f3
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert3) Is Not Null));
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert4 AS Fert, 4 AS
fert_ID, Tab_Mplant.season INTO Tab_f4
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert4) Is Not Null));
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f1.ID, Tab_f1.plant, Tab_f1.Fert, Tab_f1.fert_ID,
Tab_f1.season
FROM Tab_f1;
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f2.ID, Tab_f2.plant, Tab_f2.Fert, Tab_f2.fert_ID,
Tab_f2.season
FROM Tab_f2;
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f3.ID, Tab_f3.plant, Tab_f3.Fert, Tab_f3.fert_ID,
Tab_f3.season
FROM Tab_f3;
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f4.ID, Tab_f4.plant, Tab_f4.Fert, Tab_f4.fert_ID,
Tab_f2.season
FROM Tab_f4;
plant is different for seasons, fert1 is main fertilizer used, fert2,
fert3, fert4 would be for the secondary, auxiliary used, below is a few
records for reference:
Tab_MPlant:
ID Plant fert1 fert2 fert3 fert4 Season
1 P1 S1 S3 S2 F
2 P1 S4 S2 S1 S3 S
3 P2 S1 S3 S4 F
4 P2 S2 S1 S3 S4 S
By introducing a fert_ID and using Make Table queries and Append
queries I can finally come up the following Table:
Tab_SPlant:
ID Plant fert Fert_ID Season
1 P1 S1 1 F
1 P1 S3 2 F
1 P1 S2 3 F
2 P1 S4 1 S
2 P1 S2 2 S
2 P1 S1 3 S
2 P1 S3 4 S
3 P2 S1 1 F
3 P2 S3 2 F
3 P2 S4 3 F
4 P2 S2 1 S
4 P2 S1 2 S
4 P2 S3 3 S
4 P2 S4 4 S
However, when the plant inventory grows, a manually manipulate queries
become very cumbersome. How to make the follow process becomes
automation within Access?
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert1 AS Fert, 1 AS
fert_ID, Tab_Mplant.season INTO Tab_f1
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert1) Is Not Null));
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert2 AS Fert, 2 AS
fert_ID, Tab_Mplant.season INTO Tab_f2
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert2) Is Not Null));
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert3 AS Fert, 3 AS
fert_ID, Tab_Mplant.season INTO Tab_f3
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert3) Is Not Null));
SELECT Tab_Mplant.ID, Tab_Mplant.plant, Tab_Mplant.fert4 AS Fert, 4 AS
fert_ID, Tab_Mplant.season INTO Tab_f4
FROM Tab_Mplant
WHERE (((Tab_Mplant.fert4) Is Not Null));
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f1.ID, Tab_f1.plant, Tab_f1.Fert, Tab_f1.fert_ID,
Tab_f1.season
FROM Tab_f1;
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f2.ID, Tab_f2.plant, Tab_f2.Fert, Tab_f2.fert_ID,
Tab_f2.season
FROM Tab_f2;
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f3.ID, Tab_f3.plant, Tab_f3.Fert, Tab_f3.fert_ID,
Tab_f3.season
FROM Tab_f3;
INSERT INTO Tab_SPlant ( ID, plant, Fert, fert_ID, season )
SELECT Tab_f4.ID, Tab_f4.plant, Tab_f4.Fert, Tab_f4.fert_ID,
Tab_f2.season
FROM Tab_f4;