troubleshooting Question

ODBC SQL issue - SUM or SUMIF

Avatar of mavmanau
mavmanauFlag for Australia asked on
Microsoft SQL ServerPHPSQL
3 Comments1 Solution120 ViewsLast Modified:
ODBC SQL Query question

Hi,

We have recently upgraded some of our systems, and have changed our connectivity that some of our pages use to reach into our DB.

I have had to rewrite some of our SQL query's to suit.  We are now using an ODBC connection that talks to an SQL server in php 5.6.
the below query works:

Select dbo.client.cl_number, dbo.debtor.de_type, dbo.debtor.de_listed_date, dbo.de_transaction.tr_posted_date, sum(CASE when dbo.de_transaction.tr_account='16' then (dbo.de_transaction.tr_to_agency+dbo.de_transaction.tr_to_client)*-1 ELSE 0) FROM dbo.de_transaction LEFT JOIN dbo.debtor on dbo.de_transaction.tr_rowid_debtor = dbo.debtor.de_rowid JOIN dbo.client on dbo.client.cl_rowid = dbo.debtor.de_rowid_client where dbo.client.cl_number > '110' and dbo.client.cl_number < '119' group By dbo.debtor.de_listed_date,dbo.client.cl_number,dbo.debtor.de_type,dbo.de_transaction.tr_posted_date

apart from this part:

 sum(CASE when dbo.de_transaction.tr_account='16' then (dbo.de_transaction.tr_to_agency+dbo.de_transaction.tr_to_client)*-1 ELSE 0)

could you please help me?
The basics of it are this:  if de_transaction.tr_account = 16 then I want it to add up de_transaction.tr_to_agency and de_transaction.tr_to_client and then multiply it by -1 otherwise it equals 0.
ASKER CERTIFIED SOLUTION
Mark Wills
Topic Advisor
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros