Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Location
    OH
    Posts
    10

    Question Unanswered: Problem with CURSOR

    Hi all,
    I am trying to declare a cursor for non-select statement like this:

    Declare cur as CURSOR FOR
    Exec sproc_name

    I know that syntactically we can use only 'SELECT' statements while declaring a cursor. but I have a stored procedure which returns a result set and I want to declare a cursor for that. Is there any way that we can do this?

    Any input is highly appreciated,
    darbha.

  2. #2
    Join Date
    Dec 2002
    Posts
    63
    WHy not use a while loop instead of a cursor?

  3. #3
    Join Date
    Feb 2003
    Location
    OH
    Posts
    10
    But I need to access the result set and store the values of certain columns in local variables. And for that purpose CURSOR is the way which I know that could serve the purpose.
    I'm not sure how to access the result set from a Sproc and store the values in local variables.
    Thank you for your input.
    darbhas.

  4. #4
    Join Date
    Feb 2003
    Location
    OH
    Posts
    10
    Got it!

    What i did was used table-valued functions.


    ------------------------------
    declare @var1 as float
    declare @var2 as float
    declare @var3 as float

    Create #tmp (col1 float,col2 float,col3 float)
    Insert #tmp Exec sproc_name

    select @var1 = col1,@var2=col2,@var3=col3 from #tmp

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

    The above stores the result set from a sproc into a temporary table and then selects the values from temporary table into local variables which serves my purpose.

Posting Permissions

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