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 2005 Forums
 Transact-SQL (2005)
 Using data that was calculated on the fly

Author  Topic 

tkotey
Yak Posting Veteran

75 Posts

Posted - 2008-07-09 : 09:43:40
How does one use data that was calculated on the fly to output another data on a different field e.g.

Index	UserID	TransType	TransNum	CreateDate	Total	Balance	PreviousInvoiceBalance
1 21 1 100 6/5/2008 0:00 234 234 0
2 21 2 1 6/7/2008 0:00 40 194 234
3 23 1 101 6/7/2008 0:00 50 50 0
4 22 1 102 6/7/2008 0:00 456 456 0
5 21 1 103 6/8/2008 0:00 356 550 234


In the sample data above, the Balance is calculated on the fly and not kept in the table. I would like to use the balance
to fill in the PreviousInvoiceBalance. I know how to get these in different ways but I am having problems because the Balance is not kept in the table but outputed on the fly.

How I capture it once it is generated to output PreviousInvoiceBalance

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-07-09 : 10:21:00
You would use the same calculation you use to get balance. The bigger question for us is how do you know which row to put which previous balance on? Is UserID your record identifier? If so, then you have got the figure on line 5 wrong. Shouldn't this be 194?
Go to Top of Page

tkotey
Yak Posting Veteran

75 Posts

Posted - 2008-07-09 : 10:34:41
quote:
Originally posted by RickD

You would use the same calculation you use to get balance. The bigger question for us is how do you know which row to put which previous balance on? Is UserID your record identifier? If so, then you have got the figure on line 5 wrong. Shouldn't this be 194?



It is correct because 194 belongs to a payment but I want is the previous row with an invoice and not payment
thats why its 234 and not 194
Go to Top of Page

tkotey
Yak Posting Veteran

75 Posts

Posted - 2008-07-09 : 10:58:15
UserID is the record identifier and only get the balance of rows with TransType 1
Go to Top of Page
   

- Advertisement -