【问题标题】:How to update the data of some fields in one table based on the data of other field present on other table using LINQ or SQL?如何使用 LINQ 或 SQL 根据其他表上存在的其他字段的数据更新一个表中某些字段的数据?
【发布时间】:2012-07-04 09:35:50
【问题描述】:

我的项目中有以下视图和表格,

vw_get_arabia_upod_full_details

arabia_upod_item_avalability_master

我想根据同一张表中的 maxAllowed 和 arabia_upod_item_avalability_master 中的 availableQuantity 更新 vw_get_arabia_upod_full_details 中每个 item_id 中的数量和总价。 availableQuantity 是总数。可用的数量。因此,我需要更新每个项目的数量,检查 maxAllowed 并将 maxAllowed(或小于该值)分配给数量,直到 availableQuantity 变为零。你可以帮帮我吗?提前致谢。

【问题讨论】:

  • 视图从哪里检索 maxAllowed 字段?我问是因为修改视图以使用 availableQuantity 似乎比稍后复制此值更有效。

标签: sql sql-server tsql sql-update


【解决方案1】:
update vw_get_arabia_upod_full_details 
set
    quantity = your value
    price = ...
from vw_get_arabia_upod_full_details d
join arabia_upod_item_avalability_master m on d.id = m.id
where your condition

【讨论】:

  • 感谢您的回复。仅供参考,两个表中的 ID 都不同。我什至需要检查 availableQuantity 和 maxAllowed。
  • @JavedAhmed:当然,我已经更新了我的答案。截图很小,数据库方案我也不够清楚,请详细说明,或者尝试自己插入剩下的代码。
猜你喜欢
  • 2020-09-29
  • 1970-01-01
  • 2012-05-11
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
相关资源
最近更新 更多