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.
| Author |
Topic |
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2004-02-26 : 11:53:00
|
Here's an update queryUPDATE AAB.dbo.Absences SET FreeGuidField_01 = doel.Id FROM AAB.dbo.Absences aJOIN AAB.dbo.Absences a1 ON a.Freeguidfield_01 = a1.idJOIN ESIBS.dbo.tmpDubRef verwijder ON verwijder.HID = a1.HId AND verwijder.Verwijderen = 1JOIN ESIBS.dbo.tmpDubRef blijf ON verwijder.Referentie = blijf.Referentie AND blijf.Verwijderen = 0JOIN AAB.dbo.Absences doel ON blijf.Hid = doel.HidWHERE verwijder.referentie = '32446' I get this error: Server: Msg 8154, Level 16, State 1, Line 1The table AAB.dbo.Absences' is ambiguous.Why can I not use the target table for the update multiple times? And how do I work around that?Henri~~~Success is the ability to go from one failure to another with no loss of enthusiasm |
|
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2004-02-26 : 12:00:05
|
| After reading the BOL carefully I found it:If the table being updated is the same as the table in the FROM clause, and there is only one reference to the table in the FROM clause, table_alias may or may not be specified. If the table being updated appears more than one time in the FROM clause, one (and only one) reference to the table must not specify a table alias. All other references to the table in the FROM clause must include a table alias. I just had to 'unalias' one of the tables...Henri~~~Success is the ability to go from one failure to another with no loss of enthusiasm |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-02-26 : 12:01:08
|
| I haven't tried this but:UPDATE aSET a.FreeGuidField_01 = doel.Id FROM AAB.dbo.Absences aJOIN AAB.dbo.Absences a1 ON a.Freeguidfield_01 = a1.idJOIN ESIBS.dbo.tmpDubRef verwijder ON verwijder.HID = a1.HId AND verwijder.Verwijderen = 1JOIN ESIBS.dbo.tmpDubRef blijf ON verwijder.Referentie = blijf.Referentie AND blijf.Verwijderen = 0JOIN AAB.dbo.Absences doel ON blijf.Hid = doel.HidWHERE verwijder.referentie = '32446' |
 |
|
|
|
|
|