Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Utilizzo dell'applicazione incrociata nella dichiarazione di aggiornamento

Tu dove hai ragione, Albert. Ho fatto alcuni test e ho scoperto che è possibile, davvero. L'uso è lo stesso di un SELECT dichiarazione. Ad esempio:

UPDATE some_table
SET some_row = A.another_row,
    some_row2 = A.another_row/2
FROM some_table st
  CROSS APPLY
    (SELECT TOP 1 another_row FROM another_table at WHERE at.shared_id=st.shared_id) AS A
WHERE ...