Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure for autocalculation of columns

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-27 : 22:50:04
Rajesh writes "I have sql server7.0 & vb6.0 as a front end.
I have a logbook kind of application.
(similar to passbook entries in case of bank account)

I have a table with following columns.

(1)quantity_received(qty_issued)
(2)quantity_issued(qty_received)

(3)opening_balance(opening_bal)
(4)closing_balance(closing_bal)

The user enters values for columns (1) & (2).
columns (3) & (4) are then calculated from it.

The algorithm is as follows.
(1) for 1st record opening_bal=0 & qty_issued=0
and the user enters some value for qty_received.
so closing_bal=qty_received.

subsequently

(2) opening_balance of each record=closing_balance of the
previous record.
closing_bal of record=opening_bal of rec-qty_issued+qty_received

I wrote a stored procedure using cursors but i had to delete the
entire table & reinsert every record to take care of updates as well as inserts.Could u suggest some better solution.
Is it worthwhile to use triggers.I need all columns only while
viewing reports.

Also database normalization says that u shouldn't create
colums which are based on calculations from other columns.
so is it possible that i don't create columns for
opening & closing balance at all & still achieve my objective.

Please help me with some piece of code if possible."
   

- Advertisement -