Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Aging of item on FIFO method

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2010-06-19 : 06:25:13
I have this datas....

stockin

SELECT 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


transaction

SELECT 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.

result

SELECT 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.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-19 : 09:26:50
Are you restricted to SQL Server 2000?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2010-06-19 : 09:46:45
I am working on 2000 version. But 2005 could be utilized.

For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-19 : 09:56:40
I held a competition here about FIFO.
http://ask.sqlservercentral.com/questions/826/the-fifo-stock-inventory-sql-problem
Winning solution was explained here
http://www.simple-talk.com/sql/performance/set-based-speed-phreakery-the-fifo-stock-inventory-sql-problem/



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2010-06-19 : 10:13:36
yaiks... its 2008.

For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2010-06-22 : 06:43:37
any updates?

For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page
   

- Advertisement -