Page 1 of 1

SQL Query to find Negative Remaining Balances on Orders

Posted: Sun Mar 27, 2016 8:29 pm
by calvis
Hi There,

Can anyone kindly help me figure out some SQL code to locate negative remaining balances in orders? We normally have negative balances when customers are due refunds because they either remove items from their order or downgraded their shipping. I need some SQL Code to help me locate the negative remaining balances so we can give them refunds.

I played around with it for few hours but ran out of ideas.

Thanks


negative_balance.jpg

Re: SQL Query to find Negative Remaining Balances on Orders

Posted: Mon Mar 28, 2016 12:01 pm
by calvis
50 bucks via Paypal for someone that can help me figure this out.

Must be SQL Code.

Fields needed:

Order Number, Order Date, and Negative Balance AMT

Re: SQL Query to find Negative Remaining Balances on Orders

Posted: Tue Mar 29, 2016 12:00 am
by jmestep
Calvis, here is a basic query, but you probably want something more complicated?
select ordernumber from ac_orders where TotalCharges-TotalPayments <0

Re: SQL Query to find Negative Remaining Balances on Orders

Posted: Tue Mar 29, 2016 12:15 am
by calvis
Prefect, that got me going in the right direction. I was able to find the orders that I need to give a refund to.

Send me your Paypal address and I will shoot you a gratitude of my appreciation.

Re: SQL Query to find Negative Remaining Balances on Orders

Posted: Wed Mar 30, 2016 12:31 am
by jmestep
calvis,
I can't take a payment for that, but I do appreciate the offer. I was thinking it was going to be complicated also until I remembered that the order table had a total payments field.

Re: SQL Query to find Negative Remaining Balances on Orders

Posted: Wed Mar 30, 2016 7:01 am
by calvis
You are right, I never knew there was a TotalCharges and TotalPayments field.

I thought I was going to have to calculate those fields during the query so I could make it work. Thanks to you a few customers got their refunds that were due. :)