Solved

vb-sql programming

Posted on 2003-11-18
8
228 Views
Last Modified: 2010-04-17
i have an SQL table and want to have a Trigger for a running balance (Balance) as
Currency:       Debit:  Credit: Balance:
ZAR             10                              10
ZAR                             5               5

i have tried though not a trigger but not giving me what i want
CREATE TABLE Transactions(
   Transaction_Number NUMERIC,
   Transaction_Time TIMESTAMP,
   Account_Number INTEGER,
   Currency CHAR(8),
   Credit MONEY,
   Debit MONEY,
   PRIMARY KEY (Transaction_Number)
)
as
SELECT
   A.Transaction_Number,
   A.Transaction_Time,
   A.currency,
   A.debit,
   A.credit,
   SUM(B.Debit) - SUM(B.Credit) Balance
FROM Transactions A
JOIN Transactions B
   ON B.Account_Number = A.Account_Number
   AND B.Currency = A.Currency
   AND B.Transaction_Time <= A.Transaction_Time

GROUP BY
   A.Transaction_Number,
   A.Transaction_Time,
   A.currency,
   A.debit,
   A.credit,

ORDER BY
   A.Transaction_Time,
   A.Transaction_Number


0
Comment
Question by:gari55zw
  • 2
  • 2
8 Comments
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9770258
do you want the balance only? ie the final entry of each account? Please elorate the question
0
 

Author Comment

by:gari55zw
ID: 9770806
yes, i want the final balance after a transaction. the previous transacted balance affected by transaction type as follows,

Currency:       Debit:  Credit: Balance:
ZAR             10                              10
ZAR                             5                5
ZAR              3                               8

how do i get the balance
0
 

Author Comment

by:gari55zw
ID: 9770814
yes, i want the final balance after a transaction. the previous transacted balance affected by transaction type as follows,

Currency:       Debit:  Credit: Balance:
ZAR             10                              10
ZAR                             5                5
ZAR              3                               8

how do i get the balance
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9776328
Currency:       Debit:  Credit: Balance:
is ur input table or output format
0
 

Accepted Solution

by:
deepakshi earned 375 total points
ID: 9776955
Write the code of trigger as

CREATE TABLE Transactions(
   Transaction_Number NUMERIC,
   Transaction_Time TIMESTAMP,
   Account_Number INTEGER,
   Currency CHAR(8),
   Credit MONEY,
   Debit MONEY,
   PRIMARY KEY (Transaction_Number)
)
as
SELECT
   A.Transaction_Number,
   A.Transaction_Time,
   A.currency,
   A.debit,
   A.credit,
   SUM(B.Debit) - SUM(B.Credit)
FROM Transactions A
JOIN Transactions B
   ON B.Account_Number = A.Account_Number
   AND B.Currency = A.Currency

GROUP BY
   A.Transaction_Number,
   A.Transaction_Time,
   A.currency,
   A.debit,
   A.credit,

ORDER BY
   A.Transaction_Time,
   A.Transaction_Number



and run this trigger after u have saved the new transaction in the table.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question