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

victor gutierrez victor.gutierrez at intelygenz.com
Tue May 29 04:36:01 CDT 2007


try not using alias in the update table

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

Sarah Adams escribió:
>> does this work correctly?
>>
>> UPDATE Reservations
>>    SET ReservedBy = r2.ReservedBy
>>   FROM Reservations r
>> inner
>>   join Reservations r2
>>     on r.ParentReservationID = r2.ReservationID
>>  WHERE r.ReservedBy IS NULL
>>     
>
> Oh dear god. Even your suggestion, rudy, my favourite SQL guru, did
> not work; I got the same error message "The table 'Reservations' is
> ambiguous".
>
> I suppose I could create a copy of the table and make it work that
> way. I just hate to give in like that. But if all else fails, that's
> what I'll do.
>   


-- 
*Victor Gutierrez*

:e: victor.gutierrez at intelygenz.com
:t: 615 097 033
:msg: vgutierrez_intelygenz at yahoo.es
	*Intelygenz*
c/ Santa Engracia 151, 1ª planta, oficina 1
:cp: 28003 Madrid
:t: 91 535 96 12
http://www.intelygenz.com
Intelygenz - Tecnología transparente <http://www.intelygenz.com> 
Intelygenz - Tecnología transparente <http://www.intelygenz.com>




More information about the thelist mailing list