How can I get the result from an EXEC command

How can I get the result from an EXEC command

Post by Fred » Sat, 11 Aug 2001 00:45:19



Hi all,

I tried to get a query over an EXEC command, but I don't
know how I can store the result ?

Any idea ?

CREATE Procedure SP_xxx


as
  SET NOCOUNT ON

DECLARE





  -- At this position I want to have the returned value

  -- How I can reach this ?

 
 
 

How can I get the result from an EXEC command

Post by Val Mazu » Sat, 11 Aug 2001 00:57:36


Hi,

Try next


Val

>-----Original Message-----
>Hi all,

>I tried to get a query over an EXEC command, but I don't
>know how I can store the result ?

>Any idea ?

>CREATE Procedure SP_xxx


>as
>  SET NOCOUNT ON

>DECLARE





>  -- At this position I want to have the returned value

>  -- How I can reach this ?
>.


 
 
 

How can I get the result from an EXEC command

Post by Joshua Bec » Sat, 11 Aug 2001 03:14:27


You have a couple choices that I know of.  There are advantages and disadvantages to both but here they are:

1) global temporary table


as

create table ##tmp_output (outval int NULL)





drop table ##tmp_output

2) create a dummy stored procedure


as





drop procedure sp_dummy

------------------------------------------

The any variable created in the EXEC command exist only in the context of that command, so the outer query would not be able to access it.  That is why something must be created that spans the 2 queries (either a table or a stored procedure).  If someone knows of a way to do this without the table or sp, I'd love to hear it.

Joshua J. Beck
Automobile Protection Corporation

http://www.easycare.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

How can I get the result from an EXEC command

Post by Umachandar Jayachandra » Sat, 11 Aug 2001 03:28:46


    Here is one example:

-- In SQL70/2000





go
-- In SQL60/65/70/2000


exec('Declare evalcur Cursor FOR SELECT ' + 'ROUND(9.54,0)')
open evalcur

deallocate evalcur

--
Umachandar Jayachandran
SQL Resources at http://www.umachandar.com/resources.htm
( Please reply only to newsgroup. )

 
 
 

1. Getting a result from an EXEC'd string

Hello,

I have a rather interesting situation here. I'm trying to write a stored
procedure that will accept a database name and table name and will then
query sysindexes to find a rowcount for the table. The problem is, I

or trigger), but if I set it up with a string as the SQL statement and
use EXEC then I can't put the result into a variable. For example:
--------------------------------



--------------------------------
Does anyone know how I can get around this?

Any help is greatly appreciated.

    Thanks!
       -Tom.

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---

2. SQL 7.0/VFP 6.0 Replication/Reporting App.

3. Getting the result value for an Exec SP

4. Begineers Help with Memory Leak

5. getting return value from exec(dynamic SQL)

6. DataCombo save problem

7. Getting errors from statements executed with EXEC

8. Using a concatenated key as a primary key versus using an identity field in a table design.

9. Problem: Getting Errors from Proc w/ EXEC and RAISERROR

10. Help Getting a Return value using a Exec string

11. Creating an SQL string with exec but getting output parameters

12. partial results when stored proc exec from odbc

13. sp_executesql or Exec result value ?