Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Returning a DataSet from a Stored Procedure within a S.P.

Returning a DataSet from a Stored Procedure within a S.P.

Scheduled Pinned Locked Moved Database
databasehelpcombusinesssales
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dwatkins dirq net
    wrote on last edited by
    #1

    I've been trying to consolidate/reuse some business logic in a recent project and doing so would require me (within a MS-SQL 2000 stored procedure) to get a dataset from a stored procedure and aggregate some data. Is there a way to get a dataset from a stored procedure and put it in a temporary table? This is not an output variable, just the regular output dataset. I'm using Microsoft SQL 2000. Help please!

    USE PD9
    
    DECLARE @RC int
    DECLARE @datebegin varchar(10)
    DECLARE @dateend varchar(10)
    
    SET @datebegin = '01/01/2007'
    SET @dateend = '01/15/2007'
    
    --this is a dataset of our sales reps
    DECLARE sales_cursor CURSOR
    FOR
       	SELECT DISTINCT
    		[ABAN8]
    	FROM 
    		[vF0101_RepDetails]
    	ORDER BY [ABAN8]
    
    OPEN sales_cursor
    
    DECLARE @an8 int
    
    FETCH NEXT FROM sales_cursor INTO @an8
    
    WHILE (@@FETCH_STATUS <> -1)
    BEGIN
       IF (@@FETCH_STATUS <> -2)
       BEGIN  
    	-- i'm looping through a dataset of our sales reps
            -- now i need to get a dataset from the below sproc
            -- loop through that dataset and put it in a temp table
            -- the problem is getting the dataset from the next line - HOW??
    	-- EXEC @RC = [PD9].[dbo].[usp_rs_getSalesShipments] @an8, @datebegin, @dateend
    	-- print @RC
       END
       FETCH NEXT FROM sales_cursor INTO @an8
    END
    CLOSE sales_cursor
    DEALLOCATE sales_cursor
    

    Dirk Watkins

    A 1 Reply Last reply
    0
    • D dwatkins dirq net

      I've been trying to consolidate/reuse some business logic in a recent project and doing so would require me (within a MS-SQL 2000 stored procedure) to get a dataset from a stored procedure and aggregate some data. Is there a way to get a dataset from a stored procedure and put it in a temporary table? This is not an output variable, just the regular output dataset. I'm using Microsoft SQL 2000. Help please!

      USE PD9
      
      DECLARE @RC int
      DECLARE @datebegin varchar(10)
      DECLARE @dateend varchar(10)
      
      SET @datebegin = '01/01/2007'
      SET @dateend = '01/15/2007'
      
      --this is a dataset of our sales reps
      DECLARE sales_cursor CURSOR
      FOR
         	SELECT DISTINCT
      		[ABAN8]
      	FROM 
      		[vF0101_RepDetails]
      	ORDER BY [ABAN8]
      
      OPEN sales_cursor
      
      DECLARE @an8 int
      
      FETCH NEXT FROM sales_cursor INTO @an8
      
      WHILE (@@FETCH_STATUS <> -1)
      BEGIN
         IF (@@FETCH_STATUS <> -2)
         BEGIN  
      	-- i'm looping through a dataset of our sales reps
              -- now i need to get a dataset from the below sproc
              -- loop through that dataset and put it in a temp table
              -- the problem is getting the dataset from the next line - HOW??
      	-- EXEC @RC = [PD9].[dbo].[usp_rs_getSalesShipments] @an8, @datebegin, @dateend
      	-- print @RC
         END
         FETCH NEXT FROM sales_cursor INTO @an8
      END
      CLOSE sales_cursor
      DEALLOCATE sales_cursor
      

      Dirk Watkins

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      You can use:

      INSERT INTO #MyTempTable (col1, col2, col3, ..., coln)
        EXEC MyStoredProc
      

      where the temporary table's column list matches the columns returned in the stored procedures resultset (and their data types).

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups