从选择中更新 SQL
我想从其他表中选择更新表(商店)的两个字段,但我不知道如何做到这一点。 SQL系统是AS/400,所以没有SQL Server或Oracle技巧:(
这是SELECT
,我想要订单的价格和金额(文章表连接仅选择现有的文章)
SELECT OrderDetails.Price, OrderDetails.Amount
FROM (OrderHeader JOIN OrderDetails ON OrderHeader.Number = OrderDetails.Number)
JOIN Articles ON Article.Reference = OrderDetails.Article
WHERE OrderHeader.Store = '074'
AND OrderHeader.Date = '2009-12-04'
AND OrderHeader.Number = 26485
这是更新
,我想更新上次选择的每篇文章的价格和数量
UPDATE Store
SET Store.Price = *****OrderDetails.Price*****
, Store.Amount = Store.Amount + *****OrderDetails.Amount*****
... ????
感谢您的帮助,请原谅我的泰山英语;)
I want to update two fields of table (Store) from a select of others tables, but i don´t know how i can do it. The SQL system is in AS/400, so doesn´t have SQL Server or Oracle tricks :(
Here is the SELECT
, i want the price and amount of an order (article table join for select only existing articles)
SELECT OrderDetails.Price, OrderDetails.Amount
FROM (OrderHeader JOIN OrderDetails ON OrderHeader.Number = OrderDetails.Number)
JOIN Articles ON Article.Reference = OrderDetails.Article
WHERE OrderHeader.Store = '074'
AND OrderHeader.Date = '2009-12-04'
AND OrderHeader.Number = 26485
And here is the UPDATE
, i want update price and amount of each article from last SELECT
UPDATE Store
SET Store.Price = *****OrderDetails.Price*****
, Store.Amount = Store.Amount + *****OrderDetails.Amount*****
... ????
Thanks for the help, and excuse my Tarzan's english ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有驱动程序,您可以通过链接服务器查询执行此更新,即 SQL Server 可以将 AS/400 添加为链接服务器并对文件执行更新,我们有一个 AS400 DB2,我们通常通过 SQL Server 存储过程进行更新,但是您必须首先执行选择,然后运行更新(这是特定于供应商的 - IBM AS/400 w/DB2 和 SQL 05)
所以基本上您正在执行选择然后更新...
不知道链接服务器是否适合您,但这是一种方法。
If you have the drivers, you can perform this update via a Linked Server Query, i.e. SQL Server can add the AS/400 as a linked server and perform the update on the file, we have an AS400 with DB2, we routinely do update via SQL Server Stored Procedures, but you have to do a Select First and then run your update (this is vendor specific - IBM AS/400 w/DB2 and SQL 05)
So basically you're doing a SELECT and then an update...
Don't know if a Linked server is an option for you but this is one way.
我相信这应该有效:
WHERE EXISTS
是为了防止NULL
结果。我假设Store
有一个要匹配的id
列。仅当表针对给定的选择条件返回一行(且仅一行)时,这才有效。如果情况并非如此,您将需要提供更多详细信息。
I believe this should work:
The
WHERE EXISTS
is to prevent againstNULL
results. I'm assumingStore
has anid
column to match.This will only work if the tables will return one (and only one) row for the given selection criteria. If this is not the case, you will need to supply more details.