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

查看:283
本文介绍了如何使更新语句与3个表连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要使一条更新语句与3个表连接,连接该表的目的是更新"stockmaster"表,但是我在表格中使用了单位名称和类别名称,但是在数据库中我保存了insted的unitid和categoryid .我通过连接stockmaster.unit = stockunit.id和stockmaster.categoryid = stockcatgegory.categoryid与这三个表建立了联系.选择语句如下



i need to make an update statement connect with 3 table, the purpose of connecting the table is to update ''stockmaster'' table but i am using the unitname and category name in the form but in database i am saving the unitid and categoryid insted. i have connection with these three table by connecting stockmaster.unit = stockunit.id and stockmaster.categoryid=stockcatgegory.categoryid. the select statement as below

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.datenow  
                     FROM  StockMaster INNER JOIN  
                      StockUnit ON StockMaster.Unit =StockUnit.ID INNER JOIN  
                      StockCategory ON StockMaster.CategoryID = StockCategory.CategoryId where Itemid = 1

推荐答案

请参阅此处: http://blog.newslacker.net/2011/01/tsql-update-select .html [^ ]
see here: http://stackoverflow.com/questions/742540/tsql-update-with-insert-into-select-from[^]
or here: http://blog.newslacker.net/2011/01/tsql-update-select.html[^]


在下面的查询中使用

Hi, Use below query

UPDATE dbo.Approved
SET dbo.Approved.Groupid=dbo.Locations.ID
FROM dbo.Approved, dbo.Locations
WHERE dbo.Approved.Location = dbo.Locations.Location_Name





UPDATE dbo.Approved
SET dbo.Approved.Groupid=dbo.Locations.ID
FROM dbo.Approved inner join dbo.Locations On
dbo.Approved.Location = dbo.Locations.Location_Name


最好在单个按钮中一个接一个地分别写3个表的更新语句1_click
better write update statement for 3 tables separately one after the other in single button1_click


这篇关于如何使更新语句与3个表连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆