Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004

    Unanswered: How to get a result from a execute()

    The Transact-SQL statements in the executed string do not have access to any of the variables declared in the batch that contains the sp_executesql or EXECUTE statement. The batch containing the sp_executesql or EXECUTE statement does not have access to variables or local cursors defined in the executed string

    but I do not like to create a store procedure to get a output.
    How can I get result from execute('...') like this:
    declare @result int
    set @result=0
    execute('select @result=count(*) from table_cost')

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    You can use:
    SET @i = 0		-- Just to prove something happened
    EXECUTE sp_executesql N'SET @i = 1', N'@i INT OUTPUT', @i OUTPUT
    SELECT @i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts