Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE SET Query Fails

Status
Not open for further replies.

faccorp

Programmer
Jan 24, 2002
58
US
I'm not sure why this query fails

Code:
PARAMETERS custid Long
UPDATE CUSTOMERS
SET TOTAL = 
(SELECT SUM(DETAILS.CHARGE) FROM DETAILS WHERE DETAILS.CUSTOMER = custid)
WHERE CUSTOMERS.ID = custid;


I got the error 'operation must be an updatable query'

If I remove the (SELECT SUM() ...) and just us a number then it works fine (i.e. SET TOTAL = 10). Also, my SELECT statement only returns a single value so it should be ok too.


Thanks for any help
 
You can try like this...

Code:
PARAMETERS custid Long
UPDATE CUSTOMERS
SET TOTAL = DSUM("Charge","Details","Customer = " & CustID)
WHERE CUSTOMERS.ID = custid;

Hope this helps you...

Regards,
 
Thanks,

but i didn't give the complete query.

Instead of 'FROM DETAILS WHERE DETAILS.CUSTOMER = custid'

it's actually

FROM DETAILS INNER JOIN TRANSACTIONS ON TRANSACTIONS.ID = DETAILS.TRANID WHERE TRANSACTIONS.CUSTOMER = custid


Will the DSUM handle a join expression as the domain.

I've never used DSum before.

 
You Can try like this..

Save this part as a query

SELECT SUM(DETAILS.CHARGE) As TotalCharge FROM DETAILS INNER JOIN TRANSACTIONS ON TRANSACTIONS.ID = DETAILS.TRANID WHERE TRANSACTIONS.CUSTOMER = custid

Code:
PARAMETERS custid Long
UPDATE CUSTOMERS
SET TOTAL = DLookup("TotalCharge","<<Query Name>>");

Regards,
 
storing a calculated total breaks normalization rules, is there a valid reason for breaking the rules?


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
I did get the DLookup to work to some degree, however, why does my original query not work?

The SELECT statement only returns a single value. According to all my docs, it should work.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top