Store Query Result in Parameter

  • Hi All,

    I'm trying to store the result of a query in a parameter and haven't figured out how to do it. This is giving me errors:

    DECLARE @a INT

    SET @a = SELECT MAX(MasterID) FROM Table

    The result of the query will always be one unique number. Does anybody know how this is done?

    Thanks

  • Got it....was missing parentheses.

    This works

    DECLARE @a INT

    SET @a = (SELECT MAX(MasterID) FROM table)

  • This form will let you set more than 1 variable

    select @variable1 = column1, @variable2 = column2 from ...


    And then again, I might be wrong ...
    David Webb

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

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