Using CURSOR

  • It doesn't reset to 0 (I'm assuming you mean that you are calling another SP from the first SP, which is then reentering the first SP...).

    If you are concerned and want to check, try adding the following after calling the SP.

    print @value

    Random Technical Stuff[/url]

  • Yes, I am calling another stored procedure from within a stored procedure. I can't actually run any of the updates and inserts at this point so can't do print. Though will check it out.

    So would I do the below: (new material added in italics)

    update1

    set @value = @@rowcount

    exec dbo.storedprocedure @value

    set @value = 0.0

    update2

    set @value = @@rowcount

    exec dbo.storedprocedure @value

    set @value = 0.0

    insert1

    set @value = @@rowcount

    exec dbo.storedprocedure @value

    set @value = 0.0

    insert2

    set @value = @@rowcount

    exec dbo.storedprocedure @value

    set @value = 0.0

    insert3

    set @value = @@rowcount

    exec dbo.storedprocedure @value

    set @value = 0.0

    update3

    set @value = @@rowcount

    exec dbo.storedprocedure @value

    set @value = 0.0

    --
    :hehe:

  • No need to.

    Just run:

    set @value = 3

    exec dbo.dummystoredprocedure @value

    print @value

    where dummystoredprocedure has some sort of NOP (e.g. select 1).

    You'll see that the value after the exec doesn't change.

    Random Technical Stuff[/url]

  • ta.bu.shi.da.yu (8/6/2009)


    No need to.

    Just run:

    set @value = 3

    exec dbo.dummystoredprocedure @value

    print @value

    where dummystoredprocedure has some sort of NOP (e.g. select 1).

    You'll see that the value after the exec doesn't change.

    Meaning I need to reset it by doing set @value = 0.0, correct ?

    I want the value to change (in other words reset) because I want to pass the count of each insert / update seperately.

    --
    :hehe:

  • never mind. problem solved, dont need to initialize it, maybe Lynn meant something else and i confused it. sorry for the hi-jack.

    --
    :hehe:

  • Hi,

    Instead u can use while loop.. which will solve the problem

    Thanks and Regards

    Shyamala Shankar Raman

  • Shyamala Shankar Raman (8/12/2009)


    Instead u can use while loop.. which will solve the problem

    Sure it will, you would only have to wait longer.

    While loops are no better than cursors on the performance side. They can be even worse than cursors when the number of rows in the table exceeds a critical edge.

    I wouldn't go that way.

    -- Gianluca Sartori

  • Gianluca Sartori (8/12/2009)


    Shyamala Shankar Raman (8/12/2009)


    Instead u can use while loop.. which will solve the problem

    Sure it will, you would only have to wait longer.

    While loops are no better than cursors on the performance side. They can be even worse than cursors when the number of rows in the table exceeds a critical edge.

    I wouldn't go that way.

    I agree... I'd rewrite the code so it wouldn't call a proc on a RBAR basis. Too many people justify a loop by saying "I need it to run this stored procedure one row at a time." That's just not the correct justification.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 8 posts - 16 through 22 (of 22 total)

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