[thelist] sql update statement using a subquery (sql server)

Ken Moore psm2713 at hotmail.com
Tue May 29 14:59:20 CDT 2007

Hi all,

r937" <rudy at r937.com asked:
>does this work correctly?

That would depend on what you are trying to do :-)

Try something like this:

UPDATE Reservations
    SET ReservedBy = r2.ReservedBy
    FROM ReservedBy r, ReservationIDs r2
    WHERE  r.ParentReservationID = r2.ReservationID
         AND  r.ReservedBy IS NULL;

My SQL compiler does not work very well in emals but I think this is close.


>UPDATE Reservations
>    SET ReservedBy = r2.ReservedBy
>   FROM Reservations r
>   join Reservations r2
>     on r.ParentReservationID = r2.ReservationID
>  WHERE r.ReservedBy IS NULL

More photos, more messages, more storage—get 2GB with Windows Live Hotmail. 

More information about the thelist mailing list