如何使更新语句与3个表连接[英] How to make update statement connect with 3 tables

问题描述

你好,

我需要使用更新语句连接 3 个表,连接表的目的是更新"stockmaster"表,但我在表单中使用单元名称和类别名称,但在数据库中我保存了安装的 unitid 和 categoryid.我通过连接 stockmaster.unit = stockunit.id 和 stockmaster.categoryid=stockcatgegory.categoryid 来连接这三个表.select语句如下

SELECT StockMaster.ItemId,StockMaster.ItemCode,StockMaster.ItemName,StockMaster.ItemDescription,StockUnit.Uname,StockCategory.CategoryName,StockMaster.ManufacturedBy,StockMaster.ProductionDate,StockMaster.ExpiryDate,StockMaster.AvgCostPrice,StockMaster.StkReorderQty、StockMaster.DeleteYNID、StockMaster.UserID、StockMaster.TimeNow、StockMaster.datenowFROM StockMaster INNER JOINStockUnit ON StockMaster.Unit =StockUnit.ID INNER JOINStockCategory ON StockMaster.CategoryID = StockCategory.CategoryId where Itemid = 1
解决方案
看这里:http://stackoverflow.com/questions/742540/tsql-update-with-insert-into-select-from[^]
或在这里:http://blog.newslacker.net/2011/01/tsql-update-select.html[^]

您好,请使用以下查询

UPDATE dbo.ApprovedSET dbo.Approved.Groupid=dbo.Locations.IDFROM dbo.Approved, dbo.LocationsWHERE dbo.Approved.Location = dbo.Locations.Location_Name


UPDATE dbo.ApprovedSET dbo.Approved.Groupid=dbo.Locations.IDFROM dbo.Approved inner join dbo.位置 开启dbo.Approved.Location = dbo.Locations.Location_Name

最好在单个button1_click中一个接一个地分别为3个表编写更新语句

本文地址:https://www.itbaoku.cn/post/1395075.html