Select Statement in Update Clause

  • Hi i want to use select statement in update Clause means in a single update statement all the rows has been updated on a particular condition please provide me help thanks in advance!!

  • I am not sure if I understand your question, but you might want to give a look at the OUTPUT clause for the UPDATE statement in books online.

  • Maybe you mean something like this?

    this updates a table, and uses a SELECT to pull in relevant data from a select statement?

    [font="Courier New"]

    UPDATE SomeTable

    SET SomeTable.BudgetAmount = X.BudgetAmount

    FROM

    (

    SELECT ID,SUM(AMT) AS BudgetAmt FROM OtherTable WHERE SomeField = 1 GROUP BY ID

    ) X --aliased this select statement as X

    WHERE SomeTable.Id = X.ID

    [/font]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply