challenge
From: JT (jt_at_nospam.com)
Date: 04/29/04
- Next message: Kevin3NF: "Re: Error 3197: The Microsoft Jet database engine stopped the process because you and another user are attempting to change the same data at the same time."
- Previous message: Dan: "Re: #Temp table problem"
- Next in thread: David Browne: "Re: challenge"
- Reply: David Browne: "Re: challenge"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 29 Apr 2004 11:20:27 -0500
this procedure is working perfectly, but im having a hard time understanding
it - im wondering if someone could express this in a clearer way that would
be easier to understand (or maybe it is as clear as it can be - i don't
know)
thanks much
jt
drop table tTrans
create table tTrans(transaction_no int null, tran_type_id int null,
contract_id int null, amount money null, tran_date datetime null)
Insert Into tTrans (transaction_no, tran_type_id, contract_id, amount,
tran_date) Values (2285466, 1, 12345, 800.00, '2004-04-29 09:55:49.233')
Insert Into tTrans (transaction_no, tran_type_id, contract_id, amount,
tran_date) Values (2285470, 33, 12345, -200.00, '2004-04-29 09:56:32.543')
Insert Into tTrans (transaction_no, tran_type_id, contract_id, amount,
tran_date) Values (2285472, 33, 12345, -100.00, '2004-04-29 09:56:44.700')
Insert Into tTrans (transaction_no, tran_type_id, contract_id, amount,
tran_date) Values (2285474, 33, 12345, -50.00, '2004-04-29 09:56:57.140')
if object_id('tempdb..#TempCost') is not null
drop table #TempCost
-- Select the change
select transaction_no, tran_type_id, tran_date, amount
into #TempCost
from tTrans
where tran_type_id = 33
-- Bring in all previous items
insert into #TempCost
select t1.transaction_no, t1.tran_type_id, t1.tran_date, t2.amount
from tTrans as t1
inner join tTrans as t2 on t1.contract_id = t2.contract_id
where t1.tran_type_id = 33
and t2.tran_type_id in (1,33)
and t2.tran_date < t1.tran_date
-- End of the road
select transaction_no, sum(amount)
from #TempCost
group by transaction_no
order by transaction_no
- Next message: Kevin3NF: "Re: Error 3197: The Microsoft Jet database engine stopped the process because you and another user are attempting to change the same data at the same time."
- Previous message: Dan: "Re: #Temp table problem"
- Next in thread: David Browne: "Re: challenge"
- Reply: David Browne: "Re: challenge"
- Messages sorted by: [ date ] [ thread ]