Search code examples
sql-serversqliteinner-join

How to update the table with my inner join


I want to update the value of column PPVGLAccountID = 5. Currently it shows 81. But the problem is there are columns which doesn't below on the same table. How can I use the query UPDATE and SET?

Thank you

Please see the link

My code is:

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

but I get an error where an expression of non-boolean type specified in a context where a condition is expected.


Solution

  • IN your query there isn't correct syntax in INNER JOIN so have to slightly change it to the correct one as below and I hope you are using the correct conditions

    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
    

    Note: you can use table alias to make it easy to write and shorten the code