Need help in a query - Accessing and modifying previous row data

  • Bhuvnesh,

    I guess you have not gone through the problem fully.

    Thanks,

    Amit Khanna

  • Hi Amit Khanna,

    Thanks for ur reply. I am an asp.net developer, not a dba :rolleyes: but still i have a good knowledge on db.

    I have used joins on tables, but this CTE is something new, is it a temporary table? How and when is it populated? Actually i want to know the basics of CTE.? I know it acts like a cursor, but when should one use this CTE?

    Thanks,

    sg

  • Please go through the below link.

    ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/d4c26311-d9f4-432c-953a-1c1042b33c97.htm

  • sg (8/26/2008)


    Hi Amit Khanna,

    Thanks for ur reply. I am an asp.net developer, not a dba :rolleyes: but still i have a good knowledge on db.

    I have used joins on tables, but this CTE is something new, is it a temporary table? How and when is it populated? Actually i want to know the basics of CTE.? I know it acts like a cursor, but when should one use this CTE?

    Thanks,

    sg

    Not all CTE's are recursive... but, YES, recursive CTE's are kinda like cursors with only slightly better performance. Overall, a CTE is about the same as a "derived table" in a FROM clause, but it can be referenced more than once in the query that follows and, as you've seen, can call itself recursively.

    My recommendation is to avoid as many forms of recursion as you can including the running total recursive CTE that's been posted. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 16 through 18 (of 18 total)

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