1
update invd.InvoiceDetail set invd.costprice=883.75
from InvoiceDetail invd
where saleDespatchDetailID = 5

I'm getting an error in this query:

Msg 208, Level 16, State 1, Line 1
Invalid object name 'invd.InvoiceDetail'.

2 Answers 2

4

Since you provided an alias you will reference the alias, so the code should be:

update invd
set invd.costprice=883.75
from InvoiceDetail invd
where invd.saleDespatchDetailID = 5

But since you are not joining the table with another table, you do not actually need the alias.

update InvoiceDetail
set costprice=883.75
where saleDespatchDetailID = 5
Sign up to request clarification or add additional context in comments.

1 Comment

actually this is just a small part of my query, I join 3 tables to this query.. what ever your answer is correct. it works for me Thank you very much.
1

you are not joining in your update so you could directly execute the basic UPDATE statement.

update InvoiceDetail 
set    costprice = 883.75
where  saleDespatchDetailID = 5

In my own way of writing UPDATE statement, I only use FROM if I'm joining a table on the update statement, like this below

UPDATE a
SET    a.ColumnName = 'a'
FROM   table1 a
       INNER JOIN table2 b
            ON a.PK = b.FK
WHERE  a.Column = 'xxx'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.