简体   繁体   中英

Update records in ms access table

My current table looks as follows;

更新之前 .

I would want to be able to update this table so that it looks like this table;

更新后 .

My Goal is to update the 0 values of the PL YTD records with incremented values from PLMonthly records as shown in the 2nd screenshot. Thanks for your advice!

It is just a lot of repetition...

SELECT "PLYTD" AS Name, 
    [PL].JanActual AS JanActual, 
    [PL].[JanActual]+[PL].[FebActual] AS FebActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual] AS MarActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual] AS AprActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual] AS MayActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual]+[PL].[JunActual] AS JunActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual]+[PL].[JunActual]+[PL].[JulActual] AS JulActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual]+[PL].[JunActual]+[PL].[JulActual]+[PL].[AugActual] AS AugActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual]+[PL].[JunActual]+[PL].[JulActual]+[PL].[AugActual]+[PL].[SepActual] AS SepActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual]+[PL].[JunActual]+[PL].[JulActual]+[PL].[AugActual]+[PL].[SepActual]+[PL].[OctActual] AS OctActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual]+[PL].[JunActual]+[PL].[JulActual]+[PL].[AugActual]+[PL].[SepActual]+[PL].[OctActual]+[PL].[NovActual] AS NovActual, 
    [PL].[JanActual]+[PL].[FebActual]+[PL].[MarActual]+[PL].[AprActual]+[PL].[MayActual]+[PL].[JunActual]+[PL].[JulActual]+[PL].[AugActual]+[PL].[SepActual]+[PL].[OctActual]+[PL].[NovActual]+[PL].[DecActual] AS DecActual
FROM PL
WHERE (((PL.Name)="PLMonthly"));

Once you have that an update or append query, depending on if the PLYTD row already exists or not, and you are good to go. You can either nest it in the FROM or just build a query out of it and reference it like I did below...

UPDATE PL INNER JOIN plytd_query AS ytd ON PL.Name = ytd.Name SET 
    PL.JanActual = [ytd].[JanActual], 
    PL.FebActual = [ytd].[FebActual], 
    PL.MarActual = [ytd].[MarActual], 
    PL.AprActual = [ytd].[AprActual], 
    PL.MayActual = [ytd].[MayActual], 
    PL.JunActual = [ytd].[JunActual], 
    PL.JulActual = [ytd].[JulActual], 
    PL.AugActual = [ytd].[AugActual], 
    PL.SepActual = [ytd].[SepActual], 
    PL.OctActual = [ytd].[OctActual], 
    PL.NovActual = [ytd].[NovActual], 
    PL.DecActual = [ytd].[DecActual]

That makes some assumptions but it should get you started in the right direction anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM