execute stored procedure in a cursor for statement

  • Hi,

    Can you execute a stored procedure in a cursor? I'm trying to do the following but it causes an error:

    DECLARE budgetList CURSOR FOR

    EXECUTE up_OMS_getBudgetResults @Cost, @Stock, @pMFID, @Cost2

    ......

    Many thanks

    Reet

  • I don't believe you can, in fact, odds are you don't need a cursor.  If you post your cursor definition (which you apparently put in up_OMS_getBudgetResults) and a description of what you are trying to do, someone can most likely come up with a SET based solution for you. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • If your @Variables are already populated.  Generally after Declaring the Cursor, you populate your variables, check for errors, and run you actions through the cursor.  If you are getting an error, you may need to revisit this aspect of your code.  [Obviously, keep in mind if you are executing an SP within the actual Cursor, it will run many time...]. 

     

    I wasn't born stupid - I had to study.

  • If you want to define a cursor on the output of a sp, you need to use INSERT...EXEC into a (temp) table, then define your cursor on that table.

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

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

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