I have this datas....stockinSELECT stockin.*FROM ( select 1 as id, '2010-01-11 12:36:37.080' as transdate, 1 as itemid, 100 as QTY union all select 2 as id, '2010-02-12 11:36:37.080' as transdate, 1 as itemid, 160 as QTY union all select 3 as id, '2010-03-13 10:36:37.080' as transdate, 1 as itemid, 50 as QTY union all select 4 as id, '2010-04-10 10:36:37.080' as transdate, 1 as itemid, 200 as QTY union all select 5 as id, '2010-04-21 11:36:37.080' as transdate, 1 as itemid, 100 as QTY ) as stockin
transactionSELECT trans.*FROM ( select 1 as id, '2010-01-12 12:36:37.080' as transdate, 1 as itemid, 20 as qty union all select 2 as id, '2010-01-13 12:36:37.080' as transdate, 1 as itemid, 20 as qty union all select 3 as id, '2010-01-15 12:36:37.080' as transdate, 1 as itemid, 20 as qty union all select 4 as id, '2010-01-21 12:36:37.080' as transdate, 1 as itemid, 20 as qty union all select 5 as id, '2010-01-30 12:36:37.080' as transdate, 1 as itemid, 10 as qty union all select 6 as id, '2010-02-11 12:36:37.080' as transdate, 1 as itemid, 20 as qty union all select 7 as id, '2010-02-12 12:36:37.080' as transdate, 1 as itemid, 25 as qty ) as trans
And I want this result.resultSELECT result.*FROM ( select 1 as trans_id, '2010-01-12 12:36:37.080' as transdate, 1 as itemid, 20 as trans_qty, 80 as ending, 100 as stockin_qty, 1 as stockin_id union all select 2 as trans_id, '2010-01-13 12:36:37.080' as transdate, 1 as itemid, 20 as trans_qty, 60 as ending, 100 as stockin_qty, 1 as stockin_id union all select 3 as trans_id, '2010-01-15 12:36:37.080' as transdate, 1 as itemid, 20 as trans_qty, 40 as ending, 100 as stockin_qty, 1 as stockin_id union all select 4 as trans_id, '2010-01-21 12:36:37.080' as transdate, 1 as itemid, 20 as trans_qty, 20 as ending, 100 as stockin_qty, 1 as stockin_id union all select 5 as trans_id, '2010-01-30 12:36:37.080' as transdate, 1 as itemid, 10 as trans_qty, 10 as ending, 100 as stockin_qty, 1 as stockin_id union all select 6 as trans_id, '2010-02-11 12:36:37.080' as transdate, 1 as itemid, 20 as trans_qty, 0 as ending, 100 as stockin_qty, 1 as stockin_id union all select 6 as trans_id, '2010-02-11 12:36:37.080' as transdate, 1 as itemid, 20 as trans_qty, 150 as ending, 160 as stockin_qty, 2 as stockin_id union all select 7 as trans_id, '2010-02-12 12:36:37.080' as transdate, 1 as itemid, 25 as trans_qty, 125 as ending, 160 as stockin_qty, 2 as stockin_id union all select null as trans_id, '2010-03-13 10:36:37.080' as transdate, 1 as itemid, null as trans_qty, 175 as ending, 50 as stockin_qty, 3 as stockin_id union all select null as trans_id, '2010-04-10 10:36:37.080' as transdate, 1 as itemid, null as trans_qty, 325 as ending, 200 as stockin_qty, 4 as stockin_id union all select null as trans_id, '2010-04-21 11:36:37.080' as transdate, 1 as itemid, null as trans_qty, 425 as ending, 100 as stockin_qty, 5 as stockin_id ) as result
This is a sample output for aging of items on a FIFO basis.Can you share you're approach without using a cursor if possible?Thanks in advance...For fast result follow this...http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxWant Philippines to become 1st World COuntry? Go for World War 3...