View Full Version : SQL sum statement help


hooks
02-23-2006, 07:19 PM
I am wanting to sum up all deposits and all withdraws and get a balance. I have been unable to figure this out.

Here is my sql statement


sql = "SELECT Sum([DepositAmount])-Sum([PaymentAmount]) AS Balance " & _
"FROM(tCTransactions)" & _
"GROUP BY tCTransactions.AccountName " & _
"HAVING((tCTransactions.AccountName) = 1)"


This works fine when using access but if i use my .net program then i get the "No value given for one or more required parameters." error

What i am wanting returned is the balance only. no other fields.

thanks a bunch

Hooks

SQL_Hell
02-24-2006, 01:42 AM
Hi there

I would suggest removing the brackets around the table name in the from clause

hooks
02-25-2006, 02:43 PM
OK Here is my sql statement

SELECT Sum(DepositAmount)-Sum(PaymentAmount) AS Balance " & _
"FROM tCTransactions " & _
"WHERE tCTransactions.AccountName = 1

Im still getting the same error

SQL_Hell
02-27-2006, 02:49 AM
Hi

Can you show all your code, including ado command object as i am wondering if you have a paramater specified there.

failing that I am at a loss

hooks
03-10-2006, 12:47 AM
Sorry for not replying. I ended up working around the problem

As always thanks for the help.