Site icon Investing Blog

SQL – Update in a cross apply query

UPDATE Table1
SET SomeColumn = X.SomeOtherColumn
FROM Table1 T1
CROSS APPLY
    (SELECT TOP 1 SomeOtherColumn 
     FROM Table2 T2 
     WHERE T2.SomeJoinColumn = T1.SomeJoinColumn 
     ORDER BY CounterColumn) AS X

I want to increase CounterColumn by 1 each time the cross apply query runs. Is there any way I could achieve this?

Exit mobile version