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. 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,

  2. 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,

  3. 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