dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

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


Home > Database Forum > Microsoft SQL Server > Calculate Net Change in Previous Day Balance

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 11-18-2009, 01:28 PM
Database Newbie
 
Join Date: Nov 2009
Posts: 2
sktravers is on a distinguished road
Default Calculate Net Change in Previous Day Balance

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,
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.
Reply With Quote
  #2  
Old 02-08-2010, 03:13 AM
Database Expert
 
Join Date: Feb 2010
Posts: 42
HENARRY JAYA is on a distinguished road
Default Re: Calculate Net Change in Previous Day Balance

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,
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads

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.