get a return value

  • Hello,

            I would like to get a return value from the following query script.

    eg:

    declare @Table varchar(30)

    declare @output int

    set @Table = 'UserList'

    set @output = execute('Select count(*) from ' + @Table)

    I want to reuse that output in another query. but I have a problem.

    Thanks a lot!

     

  • To do this you must use sp_executesql

    use pubs

    declare @sql nvarchar(100),

    @Table varchar(30),

    @Output int

    set @Table = 'authors'

    set @sql = 'select @output = count(*) from ' + @Table

    exec sp_executesql @sql, N'@output int OUTPUT', @output OUTPUT

    select @Output

     

  • Thanks a lot! I got it.

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

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