August 6, 2009 at 7:53 am
Hello,
I need toi update a table with value in the same table. I give you example :
Initial table :
Item Warehouse Date Qty Amount
--------------------------------------------------
1 095 2009-05-29 625 4.53
1 095 2009-07-07 872 NULL
1 095 2009-01-01 380 3,95
2 133 2009-02-07 225 1,36
2 133 2009-04-24 152 1,36
2 133 2009-05-21 252 1,36
2 133 2009-06-22 152 NULL
3 095 2009-01-22 1410 5,54
3 095 2009-02-12 1000 NULL
3 095 2009-03-15 880 4,48
3 095 2009-04-22 1200 NULL
I just want to take the amount value of the previous line and put it to the next line if it have a null value. The result can be like this :
result table :
Item Warehouse Date Qty Amount
--------------------------------------------------
1 095 2009-05-29 625 4,53
1 095 2009-07-07 872 4,53
1 095 2009-01-01 380 3,95
2 133 2009-02-07 225 1,36
2 133 2009-04-24 152 1,36
2 133 2009-05-21 252 1,36
2 133 2009-06-22 152 1,36
3 095 2009-01-22 1410 5,54
3 095 2009-02-12 1000 5,54
3 095 2009-03-15 880 4,48
3 095 2009-04-22 1200 4,48
Thank's for helping me.
August 6, 2009 at 8:33 am
You'll need a subquery here, but you want to write this as a select. Find the rows with a null and then join that back and find the previous row.
We are happy to help, but we would like to see you make an attempt at the SQL. We don't want to be doing homework or answering interview questions for you.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply