• There is really nothing wrong with using cursors. If the application doesn't call for performance, YES cursors are quite easy to implement and everyone can read and understand them.

    I myself have used them for ages now and found that they are quite useful at times. However, now that I am in a situation where my application is in need of the full potential of the SQL server, I cannot afford to use them.

    The example posted, is just for you to measure the time that the query takes to run in your environment and to show what a resource hug a cursor could be. In my situation, the query ran for 20 seconds flat from the t-sql example provided.

    After looking at the example cursor, I can see that this will generate a huge amount of rows with the crossjoin.

    After recoding with a few select statement, I was able to make it run in less than 1 second.

    That goes to show you that cursors are very costly to run.

    Now, I am no SQL Genius but I was able to formulate the following query based on the example:

    select max(k.RowNum)

    From (

    select ROW_NUMBER() over (order by s.dta desc) as 'RowNum'

    from (

    Select 1 as Dta

    From master.sys.columns c1

    Cross Join master.sys.columns c2

    ) as s

    ) as k

    Please feel free to comment or correct if wrong or wrong approach taken.

    Al;-)