我很感激UPDATE声明提供了一些帮助。
我想使用tblOrderHead
中tblCustomer
对应参数intDocumentNo
的内容更新@intDocumentNo
。但是当我运行my语句时,订单表只会使用customer表第一行的内容进行更新。
我的逻辑有什么问题?
我使用的是Microsoft SQL Server。
谢谢,
的Stefan
UPDATE dbo.tblOrderHead
SET dbo.tblOrderHead.intCustomerNo = @intCustomerNo ,
dbo.tblOrderHead.intPaymentCode = dbo.tblCustomer.intPaymentCode,
dbo.tblOrderHead.txtDeliveryCode = dbo.tblCustomer.txtDeliveryCode,
dbo.tblOrderHead.txtRegionCode = dbo.tblCustomer.txtRegionCode,
dbo.tblOrderHead.txtCurrencyCode = dbo.tblCustomer.txtCurrencyCode,
dbo.tblOrderHead.txtLanguageCode = dbo.tblCustomer.txtLanguageCode
FROM dbo.tblOrderHead
INNER JOIN dbo.tblCustomer ON dbo.tblOrderHead.intOrderNo = @intDocumentNo
如果有人和我一样愚蠢,那就是同样的事情,这就是你解决问题的方法:
UPDATE dbo.tblOrderHead
SET dbo.tblOrderHead.intCustomerNo = @intCustomerNo ,
dbo.tblOrderHead.intPaymentCode = dbo.tblCustomer.intPaymentCode,
dbo.tblOrderHead.txtDeliveryCode = dbo.tblCustomer.txtDeliveryCode,
dbo.tblOrderHead.txtRegionCode = dbo.tblCustomer.txtRegionCode,
dbo.tblOrderHead.txtCurrencyCode = dbo.tblCustomer.txtCurrencyCode,
dbo.tblOrderHead.txtLanguageCode = dbo.tblCustomer.txtLanguageCode
FROM dbo.tblOrderHead
INNER JOIN dbo.tblCustomer ON dbo.tblOrderHead.intCustomerNo = dbo.tblCustomer.intCustomerNo
AND dbo.tblOrderHead.intOrderNo = @intDocumentNo
答案 0 :(得分:0)
问题在于,您没有指定需要加入2个表tblOrderHead
,tblCustomer
的条件!
你需要像
这样的东西INNER JOIN dbo.tblCustomer
ON dbo.tblOrderHead.someColumn = dbo.tblCustomer.someColumn
and dbo.tblOrderHead.intOrderNo = @intDocumentNo