Friday, September 16, 2011

While Loop : An SQL Server 2005 alternative for cursors

While Loop in SQL Server

SQL Server 2005 alternative for cursors is While loop. SQL Server 2005 provides a while loop which we can use to iterate through any table having at least one column. The column must have unique value (primary key is generally prefered). A sample code is provided below which is MSSQL Server Specific code and is at least 5 times faster than cursor.
Declare @PresentIDint;
Set @PresentID = (Select min(column_name) from your_table );
/*Starts the iterrational loop*/
While @PresentID is not null
/*Code segment where you have access to @PresentID*/
/*Next line required to keep iterating*/
Set @PresentID = (Select min(column_name) from your_table where column_name > @PresentID);

Relevant AD
This ad may be helpful, if relevant to your search.


Cursor is an SQL Server 2000 feature similar to the iteration loop available in the several programming languages.  The nearest match for Cursor is While loop and For Loop in the programming languages. Cursor should be avoided as much as possible.
[Did you like this post ? Do leave a comment or share with your Facebook friends. This will give me more reasons to write such posts.]


  1. Replies
    1. Great Article android based projects

      Java Training in Chennai Project Center in Chennai Java Training in Chennai projects for cse The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai

  2. toms outlet,
    nike roshe,
    prada handbags,
    soccer jerseys,
    michael kors outlet store,
    true religion jeans,
    oakley sunglasses,
    nike free 5,
    louis vuitton bags,
    chanel handbags,
    chanel handbags,
    louis vuitton handbags,
    louis vuitton outlet,
    ghd hair straighteners,
    nba jerseys,
    coach outlet,
    true religion jeans,
    swarovski crystal,
    mbt shoes,
    michael kors handbags,
    chanel handbags,
    michael kors outlet online,
    polo ralph lauren,
    the north face clearance,
    jordan shoes,
    beats by dr dre,
    the north face uk,

  3. steelers jerseys,
    michael kors handbags,
    cheap ugg boots,
    kobe bryants shoes,
    louis vuitton handbags outlet,
    true religion outlet,
    cheap nba jerseys,
    san antonio spurs,
    tiffany and co,
    wellensteyn outlet,
    adidas outlet,
    canada goose outlet,
    michael kors outlet,
    bottega veneta outlet,
    canada goose outelt,
    hollister shirts,
    tiffany and co,
    swarovski outlet,
    basketball shoes,basketball sneakers,lebron james shoes,sports shoes,kobe bryant shoes,kobe sneakers,nike basketball shoes,running shoes,mens sport shoes,nike shoes
    winter jackets,

  4. Kendall Jenner’s the model of the moment. Having walked for the likes of Chanel, Dolce and Gabbana, Fendi, Marc Jacobs and Givenchy she is racking up a cheap ray ban sunglasses sale under 30$ serious CV. Victoria Beckham is said to have earmarked her for her next catwalk show. Having met with her recently the designer is cheap ray bans said to have called her the most naturally beautiful model.All that catwalk dressing is giving her some great styling sense. At Geoffrey’s in ray ban outlet Malibu she’s out celebrating her dad’s birthday with sister Kylie and half sisters Kim, Khloe and Kourtney. Like many a model that has Ray Ban Sunglassses Sale access to top designer sunglasses from the big fashion houses Ray-Ban is still a go-to. She coordinates her look with the Ray-Ban 3025 cheap ray bans for sale Aviator with gold frame and blue lens. The gold frame is synced up with her sandals, gold bag hardware, watch and ring. The ray ban sunglasses pale blue gradient lens is the perfect compliment to that pale pink jump suit. The aviator shape does a good job of toughening ray ban store up that pink too.
    That the peaks of red carpet dressing leave A list ladies hankering for high glamour off duty is ray ban aviators no surprise. Fine designer sunglasses are one the first ports of call. Actress Amy Adams is currently the face for MaxMara. But she’s cheap ray ban sunglasses forgoing the house for another Italian legend when it comes to sunglasses though here.Shopping with the family in Los Angeles she’s wearing Bulgari Ray Ban Sunglassses

  5. Burial will follow in Peninsula Memorial Park. The family wishes to thank Dr. Frank Huffman, the nursing staff and the Newport News Baptist Retirement Community for the love and concern she received. Our global image is being questioned. Our democracy is being questioned. After the total lockdown, we are Coach Outlet Store unable to provide them 4G connections.

    The geobody dimensions appear to be related to the strain magnitude of the strike slip faults. Coach Outlet We propose that these identified New Jordan Shoes 2020 links and controls are applicable to structurally controlled dolomitization on a more general basis. Our study has demonstrated the potential for using drones in carbonate geological studies..

    People who intentionally starve themselves suffer from an eating disorder called anorexia nervosa. The disorder, which usually begins in young people around the time of puberty, Coach Handbags Clearance involves extreme weight loss that is Ray Ban Outlet less Yeezy Boost 350 than what is considered minimally normal.People with the disorder will often look emaciated, but are convinced that they are overweight. Sometimes they must be hospitalized Ray Ban Glasses in order to prevent starvation.People with anorexia typically starve themselves, Yeezy Discount even though they terribly suffer from hunger pains.

  6. You will agree with me that women are generally synonymous to fashion. And one of the fashion Coach Handbags Clearance that women adore so much when they want to look fashionable and thus look beautiful, is fine looking attractive and quality New Air Jordan Shoes. Thus, in as much as women love putting on quality fine looking Cheap Air Force Ones, research has confirmed that women just don't throw money around like their opposite counterpart, so quality fine looking MK Outlet they prefer, but they also prefer buying them cheap. An increasing number of people these days are finicky about the kind of Air Jordan Sale they wear. While almost everyone wants to wear the latest Michael Kors Factory Outlet and trendiest Cheap Yeezys not many are prepared to shell out exorbitant amounts of money for these. Therefore, if you want to know insider secrets to buy cheap Coach Factory Outlet Online read on to know more. (Article Source From Coach Outlet Clearance Sale)

  7. Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great

  8. A debt of gratitude is in order for your post. I've been contemplating composing an extremely tantamount post in the course of the last couple of weeks, I'll most likely keep it straightforward and connection to this rather if thats cool. Much obliged.미프진