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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jojns driving me crazy!! pls Help 1

Status
Not open for further replies.

Forri

Programmer
Oct 29, 2003
479
MT
Hi all

I have the following Sql and it should get the whole list of customers and a total as debit from the client_trans table but it is only giving me one result! Why is this so and is it an efficient sql (after it works) or is there a more efficient manner!!

SELECT

(case when (sum(T.t_Debit) - sum(T.t_Credit)) > 0 then
(sum(T.t_Debit) - sum(T.t_Credit)) Else 0 End) as Debit

FROM CustomersDB as C join Client_Trans as T on c.Cust_Id = T.t_ClientID


Thanks
N
 
Is this what you want?

SELECT c.Cust_Id,
SUM(case when (T.t_Debit - T.t_Credit) > 0 then
(T.t_Debit - T.t_Credit) Else 0 End) as Debit
FROM CustomersDB as C join Client_Trans as T on c.Cust_Id = T.t_ClientID
group by c.Cust_Id
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top