开发者

C# Access Database Question

开发者 https://www.devze.com 2023-02-09 07:07 出处:网络
Say i have 2 tables now, PricePlan and Bill. Both ta开发者_高级运维bles have a column called \'Price\' and I would like the table \'Bill\' to update the value from \'PricePlan\'s Price. How can i do t

Say i have 2 tables now, PricePlan and Bill. Both ta开发者_高级运维bles have a column called 'Price' and I would like the table 'Bill' to update the value from 'PricePlan's Price. How can i do this or what SQL statement should i be using? Thanks in advance!


You will need to have some sort of way to define a relationship between the two tables.

For instance if your tables have this structure:

PricePlan
---------
ID
Price

Bill
---------
PricePlanID
Price

This will only work for SQL Server. See below for Access solution.

Then a query like this should update Bill :

UPDATE b SET b.Price = pp.Price
FROM Bill as b
INNER JOIN PricePlan as pp
ON b.PricePlanID = pp.id

Also, the schema above is only for example purposes. If yours is like that you should look at changing it.

UPDATE

I just noticed this is for Access, sorry. The strucure of your query will be slightly different. See below:

UPDATE Bill INNER JOIN 
PricePlan ON Bill.PricePlanID = PricePlan.ID
SET Bill.Price= [PricePlan].[Price];


making some wide assumptions here, but i think this short tutorial on cascading updates in access 2010 should get you on your way.

0

精彩评论

暂无评论...
验证码 换一张
取 消