What would be the correct syntax, if any, that allows updating a table
variable in a statement that uses the same table variable in a correlated
subquery? Here's an example:
DECLARE @t table (N1 int NOT NULL, N2 int NOT NULL)
UPDATE @t SET
N1 = (SELECT COUNT(1)
FROM @t AS t
WHERE t.N2 < @t.N2)
This doesn't compile, complaining about "variable @t" in the WHERE clause.
I'm not so interested in a way to rewrite this particular statement to make
it work, but rather in a general way to refer to table variables in the
contexts where correlation names cannot be used.
Thank you.
--
remove a 9 to reply by email
variable in a statement that uses the same table variable in a correlated
subquery? Here's an example:
DECLARE @t table (N1 int NOT NULL, N2 int NOT NULL)
UPDATE @t SET
N1 = (SELECT COUNT(1)
FROM @t AS t
WHERE t.N2 < @t.N2)
This doesn't compile, complaining about "variable @t" in the WHERE clause.
I'm not so interested in a way to rewrite this particular statement to make
it work, but rather in a general way to refer to table variables in the
contexts where correlation names cannot be used.
Thank you.
--
remove a 9 to reply by email
Comment