Using cross apply in update statement

25,401

You where right, Albert. I made some tests and found that it's possible, indeed. The use is the same as in a SELECT statement. For example:

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 ...
Share:
25,401
Guillermo Gutiérrez
Author by

Guillermo Gutiérrez

Currently Javascript Senior Developer. I have experience primarily with C# and SQL Server, which I used the most in last 2 jobs. Also I have been using Developer Express components for Windows Forms and ASP.NET MVC Framework. Aditionally I have knowledges in relational database design. Currently I am also learning Elixir, Erlang and Clojure (I love FP!) In web development (which I like the most and is what influenced me to choose this career :), I have experience with: HTML, CSS and Javascript. JQuery and some AngularJS. Bootstrap framework. Symfony PHP Framework 1.4 and 2, combined with Doctrine 1 and 2 ORM. Experience on ASP.NET MVC Framework, Web API, NHibernate, FluentNHibernate, FluentValidation and StructureMap. Basic knowledges of ServiceStack. Mobile applications with Phonegap/Cordova, using Intel's AppFramework, and now starting with Onsen UI. Scala, with Play Framework, Akka and Slick (still learning). Other programming languages I have used: C, Visual Basic 6 and .NET, DrScheme, Prolog.

Updated on June 27, 2020

Comments

  • Guillermo Gutiérrez
    Guillermo Gutiérrez about 4 years

    Is it possible to use the cross apply clause in the from part of an update statement, in SQL Server 2005?