Assigning variables with Dynamic SQL

  • I have a dynamic sql statement that returns an integer value like so.

    Exec sp_executesql @sql

    How do I assign the result of the dynamic sql to a variable

    Declare @num as int

    Select @num = Exec sp_executesql @sql

    Thanks in advance

  • Look at output parameters. You can pass the variable as an output parameter to your dynamic sql and assign it there

    Regards

    Piotr

    ...and your only reply is slàinte mhath

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

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