MERGE su una table variable (2)
Sempre a proposito del "Merge su una variabile di tipo tabella" - della quale limitazione avevo parlato nel mio post precedente -, subito dopo aver scritto il post ho inserito un commento su Microsoft Connect.
Per chi non lo conoscesse, si tratta del sito col quale è possibile dare dei feedback sui prodotti Microsoft e segnalare eventuali bug a cui Microsoft risponde direttamente - aprendo eventualmente una risoluzione dell'anomalia riscontrata.
In poco più di 3 giorni il suddetto commento ha ottenuto una risposta esauriente dal SQL Programmability Team, che riporto fedelmente a beneficio di chi si fosse interessato alla questione:
Hi Francesco,
Thanks for reporting this issue. We are aware of the
limitation in using table variable names instead of aliases in certain
constructs of DML statement(s). For example, below code will also raise
error:
create table #t ( i int );
declare @t table ( i int );
update #t
set i = @t.i
from #t join @t
on #t.i = @t.i;
go
drop table #t;
go
We will consider removing the restriction in a future version of SQL
Server. This is not a syntax change that we will make to SQL Server
2008 though.
For now, the workaround is to alias table variables
explicitly and use them. This also improves readability of the
statement in general.
--
Umachandar, SQL Programmability Team