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)
 Update Question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-24 : 12:34:53
Mikhail Goncharov writes "I have two tables having one to one relationship and

I need to update one of the tables with the summary (sum)
of calculating values from the related table.

Example:

Table MemCharges (ChargeID(int),
MemberID(int),ChDate (date), Amount (smallmoney), Status(tinyint))

storing the charges for each member and dates
and status for the charge (1-approved, 2- declined).

Table MemPaid (MemberID, Tot_Paid(smallmoney))

storing the results of membecharges for the reporting,
total amount of the money paid by each
member to date, approved only.

I can update it now using the T-SQL cursor and then doing SUM for each row in memcharges table and then updating the MemPaid Table. Unfortunately it works pretty slow because
I have approximately 3000 records in MemPaid table and 15000 in
MemCharges Table.

Is there anyway of doing it in one SQL statement ?"
   

- Advertisement -