RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums
Views: 1248 | Replies: 1
Reply
Join Date: Apr 2007
Posts: 1
Reputation: SQLUser is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SQLUser SQLUser is offline Offline
Newbie Poster

Question Reconciliation using Cursor

  #1  
Apr 24th, 2007
I have two record sets. One is transactions and another is GL posting. I am aiming to create a third table to find out the customers are from which country inflate our GL.

For example GL Table has following fields
GLCode
GLDescription
GLAccount
GLAccountCCY
Balance
BalanceUSD

Transaction Table has the following fields
TxnID
TxnDate
ProductID
TxnAmount
TxnCCY
TxnAmountUSD
CustID
GLAccount

Some GLAccounts are straight populated from transaction and some are not. Hence when I take a sum of TxnAmountUSD on GLAccount and TxnCCY and try to match with the sum of BalanceUSD on GLAccount and GLAccountCCY from GL Table it does not match.

The third table I need to create is a reconciliation table and requirement is if I take total of GL table on GLCode it should match with the GLCode in newly crated table (ReconTable). ReconTable should contain all the records from Transaction table. In addition to that new records will be inserted for each GLAccount and CCY combination whose amount does not match with GL.

I am thinking of using CURSOR. The cursor will read value from transaction table and match the figure with GL. If does not match, will create a record with the difference value and insert the ReconTable along with the transaction records. Is this a right approach or is there a better way out?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Location: London
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: Reconciliation using Cursor

  #2  
Apr 24th, 2007
A simple insert should do the job just as well.

Assuming your table has the simplest possible definition

Reconciliation table
GLAccount
TxnID
ReconciliationType (Txn or Rec)
TxnDate
TxnAmount

You could write it as follows (example uses two statements, you could use one with a union clause if you like)

INSERT INTO Reconciliation (GLAccount, TxnID, ReconciliationType, TxnDate, TxnAmount)
SELECT GLAccount, TxnID, 'Txn', TxnDate, TxnAmount
FROM Transaction

INSERT INTO Reconciliation (GLAccount, TxnID, ReconciliationType, TxnDate, TxnAmount)
SELECT g.GLAccount, Null, 'Rec', getdate(),
Sum(g.BalanceUSD) - Sum(isnull(t.TxnAmountUSD, 0))
FROM GL as g
LEFT JOIN
Transaction as t
ON g.GLAccount = t.GLAccount
GROUP BY g.GLAccount
HAVING Sum(g.BalanceUSD) - Sum(isnull(t.TxnAmountUSD, 0)) <> 0

Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:16 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC