SQL sum statement help (1 Viewer)

hooks

Registered User.
Local time
Today, 00:46
Joined
Aug 13, 2004
Messages
160
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

Code:
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

SQL Server DBA
Local time
Today, 08:46
Joined
Dec 4, 2003
Messages
1,360
Hi there

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

hooks

Registered User.
Local time
Today, 00:46
Joined
Aug 13, 2004
Messages
160
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
 
Last edited:

SQL_Hell

SQL Server DBA
Local time
Today, 08:46
Joined
Dec 4, 2003
Messages
1,360
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

Registered User.
Local time
Today, 00:46
Joined
Aug 13, 2004
Messages
160
Sorry for not replying. I ended up working around the problem

As always thanks for the help.
 

Users who are viewing this thread

Top Bottom