ODBC SQL issue - SUM or SUMIF

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.
mavmanauNetwork Engineer/SysadminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark WillsTopic AdvisorCommented:
Well, your CASE is missing an END

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 END)

Apart from that - the arithmetic looks fine.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mavmanauNetwork Engineer/SysadminAuthor Commented:
Thank you. Can’t believe I missed that!
0
Mark WillsTopic AdvisorCommented:
A pleasure, and easy enough to do, we all have - at some point in time - even multiple times :)

Many eyes makes light work - and that is what we are here for :)

Cheers,
Mark Wills
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.