Remove cursors without using while loop

  • Remove cursors without using while loop

  • We can't do that unless we see the rest of the code and the code of the calling objects.

  • yep Ninja's right; the key is the procedure usp_generate_purchase_order and the code you commented out ; whatever it is doing to a single set of parameters needs to be moved into a set based command...

    can't suggest anything until we see what that does.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for your responce. actually i copied somewhere that above code.

  • mahe2682 (5/20/2011)


    ...

    can u help me for this.

    ...

    Look up the OUTPUT clause in Books Online.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • There's no way I'd ever do that job from a forum.

    Hire pro.

  • Ninja's_RGR'us (5/20/2011)


    There's no way I'd ever do that job from a forum.

    Hire pro.

    It's not as tough as it looks Ninja - it's an INSERT from a SELECT, OUTPUTting the new ID's which are then used for an UPDATE. Providing OP grasps OUTPUT, job done. If not, hire pro 😉


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • I think Chris is right. You could output the fields you need into a temp table and use that to perform the update. Can you provide some table layouts, sample data and what you would expect the results to be?

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • ChrisM@home (5/20/2011)


    Ninja's_RGR'us (5/20/2011)


    There's no way I'd ever do that job from a forum.

    Hire pro.

    It's not as tough as it looks Ninja - it's an INSERT from a SELECT, OUTPUTting the new ID's which are then used for an UPDATE. Providing OP grasps OUTPUT, job done. If not, hire pro 😉

    I'm not touching a wire banking system without making sure the changes are correct ;-).

  • ...buth this random guy on the interwebz gave me the code to make this run faster ...what do you mean the numbers are off?...

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I agree. While I could certainly rewrite the code, I wouldn't want to touch a banking system without a lot more information on what this does and why.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Lowell (5/20/2011)


    ...buth this random guy on the interwebz gave me the code to make this run faster ...what do you mean the numbers are off?...

    Never a better time to say this>

    Put your money where you mouth is :w00t:!

  • Ninja's_RGR'us (5/20/2011)


    ChrisM@home (5/20/2011)


    Ninja's_RGR'us (5/20/2011)


    There's no way I'd ever do that job from a forum.

    Hire pro.

    It's not as tough as it looks Ninja - it's an INSERT from a SELECT, OUTPUTting the new ID's which are then used for an UPDATE. Providing OP grasps OUTPUT, job done. If not, hire pro 😉

    I'm not touching a wire banking system without making sure the changes are correct ;-).

    Neither am I - hence the suggestion rather than code 😎


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • I tried to myself and removed the cursors. but I wants to do without while loop also

  • Have you read any of the comments that have been posted to this thread?:ermm:

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 15 posts - 1 through 15 (of 23 total)

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