• kishorefeb28 (1/31/2014)


    Hi Experts,

    i need to write a stored procedure for a table with below columns

    for instance the table had 5 columns like

    VendorCode | UnitPrice | Qty | Total(UnitPrice*Qty) |

    --------------------------------------------------------

    V001 | 100 | 10 | 1000

    V001 | 10 | 20 | 200

    V222 | 20 | 5 | 100

    V222 | 5 | 100 | 500

    so am writing a Stored Proc to get all the table values like above ., but i need to write Stored Proc in such a way it returns

    the above table like result along with subtotal when ever vendor code changed. as below

    VendorCode | UnitPrice | Qty | Total(UnitPrice*Qty) |

    --------------------------------------------------------

    V001 | 100 | 10 | 1000

    V001 | 10 | 20 | 200

    subtoal 110 30 1200 ----- this subtoal should be displayed from Stored procedure

    V222 | 20 | 5 | 100

    V222 | 5 | 100 | 500

    subtotal 25 105 600

    please help me to acheive this

    thank you.

    Use GROUP BY WITH ROLLUP. See Books Online. As the others have suggested, if you want a coded answer, please see the first link in my signature line below under "Helpful Articles".

    --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)