Solved

vb-sql programming

Posted on 2003-11-18
8
226 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
Comment Utility
do you want the balance only? ie the final entry of each account? Please elorate the question
0
 

Author Comment

by:gari55zw
Comment Utility
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
Comment Utility
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
Comment Utility
Currency:       Debit:  Credit: Balance:
is ur input table or output format
0
 

Accepted Solution

by:
deepakshi earned 375 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now