Calculate Net Change in Previous Day Balance - Microsoft SQL Server
This is a discussion on Calculate Net Change in Previous Day Balance - Microsoft SQL Server ; I want to create a calculated field that compares results between two records. When I run the following query: declare @BusDate as datetime set @BusDate = '11/11/2009' select @BusDate as Busdate, '1600-02-' + AcctgCAcctGLMap.GLCode + '-' + AcctgCurr.GLCurrCode as GLaccount, ...
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| When I run the following query: declare @BusDate as datetime set @BusDate = '11/11/2009' select @BusDate as Busdate, '1600-02-' + AcctgCAcctGLMap.GLCode + '-' + AcctgCurr.GLCurrCode as GLaccount, 0 as DebitPostval, vw_SelectFBalance.Lval as CreditPostVal, 'Bal:LValue' as Desc from vw_SelectFBalance Bal, AcctgCAcctGLMap ACAG, AcctgCurr Curr where Bal.CFirm = ACAG.CFirm and Bal.Account = ACAG.CAcct and Bal.BalanceCurrency = Curr.CurrencyCode and OfficeCode <> 'RPT' and BusinessDate = @BusDate and Lval > 0 I get the following results: Busdate GLaccount DebitPostval CreditPostVal Desc 2009-11-11 1600-02-F0-00 0 58470.00 Bal:LValue 2009-11-11 1600-02-F1-00 0 7930.00 Bal:LValue 2009-11-11 1600-02-F3-00 0 22186.60 Bal:LValue What I want to do is pull the same information from the previous day, subtract the LVal balance from the LVal for the current day, and create a new field called NetChange. If the data for the previous day is as follows: Busdate GLaccount DebitPostval CreditPostVal Desc 2009-11-11 1600-02-F0-00 0 8470.00 Bal:LValue 2009-11-11 1600-02-F1-00 0 7000.00 Bal:LValue 2009-11-11 1600-02-F3-00 0 23000.00 Bal:LValue My results should be: Busdate GLaccount Net Change Desc 2009-11-11 1600-02-F0-00 0 8470.00 Bal:LValue 2009-11-11 1600-02-F1-00 0 930.00 Bal:LValue 2009-11-11 1600-02-F3-00 0 -813.40 Bal:LValue I think I need to join by GLaccount but need help with the syntax. |
|
#2
| |||
| |||
|
A very warm welcome to you.... This is my second post in this forum, I really enjoyed the way existing members are greeting new members.... It's really a very nice and interactive forum, I feel great I landed here.... Regards, |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SQL 2008 AS, RS, and SSIS fail on OWC11 | Database Administrator | sqlserver-faq | 1 | 08-14-2008 10:28 PM |
| comp.sys.hp.hpux FAQ | Database Administrator | Answers and FAQ | 0 | 02-16-2008 01:22 AM |
| comp.sys.hp.hpux FAQ | Database Administrator | Answers and FAQ | 0 | 11-20-2007 01:24 AM |
| comp.sys.hp.hpux FAQ | Database Administrator | hp-hpux | 0 | 11-20-2007 01:24 AM |
| comp.sys.hp.hpux FAQ | Database Administrator | Answers and FAQ | 0 | 11-10-2007 01:21 AM |
All times are GMT -4. The time now is 03:46 PM.




Linear Mode
