Alternative to cursors

  • Hi,

    Are there any constructs which provide same functionality of cursors

    Thanks

  • Yes.

    (And if you want a better answer, ask a more specific question.)

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • And if you look around this forum, you will also find that for 99.9% of the time that you think you need a cursor, guess what, you don't.

    A majority of the time there is probably a set-based solution that is both faster and more scalable than a cursor-based solution.

  • the classic scenario is a while loop:

    declare @i tinyint

    set @i = 1

    while @i < 10

    begin

    do something here

    set @i = @i + 1

    end

    obviously you can do lots of things with @i or the comparison in the while...

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 4 posts - 1 through 3 (of 3 total)

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