Friday, May 11, 2012

How to make an update query using join in SQL

Today it helped me a lot this page which instructed me how to make an update query using join. So you can go and check it out on http://www.bennadel.com/blog/938-Using-A-SQL-JOIN-In-A-SQL-UPDATE-Statement-Thanks-John-Eric-.htm

Here you can see how I wrote my update command:


                        UPDATE  O
set O.Payed = Payed - 1, O.PaymentDate = null , refPaymentMethodId = null
from [Orders] O
join PaymentMethod pm on pm.PaymentMethodID = O.refPaymentMethodID
where OrderID = @OrderID and pm.GenerateReceipt = 1;
Cheers.

No comments:

Post a Comment