Nested Update Statement

  • I am trying to write a script that will automatically update. I'm thinking I need a nested update statement with the possibility of using a temp table or table variable.

    Here is my manual process:

    --first I grab all the ID's that have a status of 4

    Select MessageID

    From MessageQueue

    Where MessageStatusID = 4

    --Then I put the messageID's from the results of the above query into the where clause

    UPDATE MessageQueue

    SET MessageID = 1

    WHERE MessageID in (<results from above query>)

    Thanks in advanced!

  • greggoble2 (1/14/2010)


    --first I grab all the ID's that have a status of 4

    Select MessageID

    From MessageQueue

    Where MessageStatusID = 4

    --Then I put the messageID's from the results of the above query into the where clause

    UPDATE MessageQueue

    SET MessageID = 1

    WHERE MessageID in (<results from above query>)

    This seems overcomplicated to me. Wouldn't it be easier to do this . . . ?

    update MessageQueue

    set MessageID = 1

    where MessageStatusID = 4

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

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

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