如何使用我的内部联接更新表

时间:2018-09-22 00:45:33

标签: sql-server sqlite inner-join

我想更新列PPVGLAccountID = 5的值。目前显示81。 但是问题是同一表中没有下面的列。 如何使用查询UPDATE和SET?

谢谢

Please see the link

我的代码是:

UPDATE dbo.POInvoicingDetails
SET PPVGLAccountID = '5'
FROM dbo.POInvoicingDetails
INNER JOIN dbo.POInvoicing PPVGLAccountID ON dbo.POInvoicingDetails.POInvoicingID
WHERE dbo.POInvoicing.InvoiceNo = '421009'

但是在需要条件的上下文中指定非布尔类型的表达式时,我得到一个错误。

2 个答案:

答案 0 :(得分:1)

我想这就是你想要的:

UPDATE id
SET PPVGLAccountID = '5'
FROM dbo.POInvoicingDetails id INNER JOIN
     dbo.POInvoicing i
     ON id.POInvoicingID = i.POInvoicingID
WHERE i.InvoiceNo = '421009';

您的ON子句缺少JOIN条件。

答案 1 :(得分:0)

在您的查询中,INNER JOIN中的语法不正确,因此必须将其略微更改为如下所示的正确语法,希望您使用的条件正确

UPDATE dbo.POInvoicingDetails
SET PPVGLAccountID ='5'
FROM dbo.POInvoicingDetails
--Condition were missing in the below line compare below line you will get the point
INNER JOIN dbo.POInvoicing ON dbo.POInvoicing.POInvoicingID = dbo.POInvoicingDetails.POInvoicingID
WHERE dbo.POInvoicing.InvoiceNo = '421009' 

'421009'--Should not in the quote if it's not `STRING or CHARACTER` type

注意:您可以使用表alias来简化代码编写和缩短代码