Small Help

  • Gurus

    I have a table like

    OrderNo OrderDate Cost PreviousCost NewCost

    1 10/20/2009 100 100 0

    2 10/19/2009 200 0 200

    1 10/20/2009 10 0 10

    If the same orderno exists in previous month, then update the precost column with current Cost other wise update the newcost column with current Cost

    Thanks.

    007

  • This is not an easy one, but it's doable. Do you have anything you have come up with, what are you working on right now?

    Can you provide some testing data, so we don't have the idea of working alone on your solution! 😛

    Sorry to say, but, help us help you, show us what you've come up with, and prepare the table with some sample data for us, as well as expected results.

    Cheers,

    J-F

  • Here is my intial table looks like

    OrderNo OrderDate Cost PreviousCost NewCost

    1 10/20/2009 100 0 0

    2 10/19/2009 200 0 0

    1 10/20/2009 10 0 0

    After the update statement ( Solution ) ran table looks like

    OrderNo OrderDate Cost PreviousCost NewCost

    1 10/20/2009 100 100 0

    2 10/19/2009 200 0 200

    1 10/20/2009 10 0 10

    Let me know if you need more info ?

    Thanks

    007

  • Well, it's a start, but you have not prepared the tables using Create table TableA, and most importantly, INSERT INTO Table

    select bla bla bla

    union all

    select bla bla bla

    union all ....

    And by the way, your data (3 rows), are all in the same month, we 'll need more test data than this before we can test our solution, since it needs to be based from last month.

    Cheers,

    J-F

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

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