I think I'm losing my mind here. I try to update a specific subset of Table1
. Let's say the SELECT
from Table1
returns 1 million rows. For each of these rows, I want to cross apply a specific calculated sum from Table2
.
I know for a fact that not all rows in Table1
can be joined to Table2
with the conditions in the CROSS APPLY
part.
The update still says 1,000,000 row(s) affected. After this I got suspicious and added the '1 = 0' condition to the CROSS APPLY
so it could never return a row.
But it still updates all rows in Table1
?
UPDATE T1
SET T1.Field1 = T2.SumField
FROM
(
SELECT *
FROM Table1
WHERE ....
) T1
CROSS APPLY
(
SELECT SUM(Field1) SumField
FROM Table2
WHERE [A lot of Fields] = [Some Values from T1]
AND 1 = 0 -- !!!
) T2
Does anyone know why this happens?