Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with update query

Author  Topic 

BrianBurgit
Starting Member

12 Posts

Posted - 2009-12-16 : 15:52:42
I have a select query that finds records ready for payment, like this

SELECT P.ID, P.Amount
FROM Payments P INNER JOIN HotelBookings H ON P.Segnum = H.Segnum WHERE H.ArrivalDate) Between [Starting Hotel Arrive Date] And [Ending Hotel Arrive Date])

This works fine. I now would like to UPDATE the Payments Table, setting the DatePaid field to the current date. I'd like to do something like this

UPDATE Payments
SET DatePaid = GetDate()
WHERE H.ArrivalDate) Between [Starting Hotel Arrive Date] And [Ending Hotel Arrive Date])

but of course this doesn't quite work. How can I use the HotelBookings Table in my Update query?

Thanks,

Brian

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-16 : 15:53:58
UPDATE P
SET DatePaid = GetDate()
FROM Payments P
JOIN HotelBookings H
ON P.Segnum = H.Segnum
WHERE H.ArrivalDate Between [Starting Hotel Arrive Date] And [Ending Hotel Arrive Date]


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -