exec a stored procedure in a cursor

  • I have a stored procedure that gives me a recordset based on a salesman ID.

    I would like to use this within a Cursor loop.

     Declare SalesCursor Cursor
     For Exec dbo.GetSales @SalesID, @StartDate, @EndDate

    The SQL parser does not like this statement. Is there another way to do this?

    Should I change the SP to a function?

    Thanks,

    Bryan Clauss

  • -- Create temp table with the structure of Data returned by the Sproc

    CREATE TABLE #temp

    (

    col1 INT NULL,

    col2 varchar(2) NULL

    )

    INSERT INTO #temp (col1, col2) Exec dbo.GetSales @SalesID, @StartDate, @EndDate

    -- Use #temp in Cursor

    DROP TABLE #temp

    Tim S

  • Thanks a Bunch!

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

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