I need help to calculate the turnaround time of any account in order to become positive with a negative daily balance. For example, the account 12345 is positive on 04/05/2013, but has a negative balance on 04/06, 04/07, 04/08 (three days), and on the fourth day it became positive. I would like to develop a query to calculate turnaround time (4 days).
Account Number Transaction Date Daily Balance 12345 4/1/2013 304 12345 4/2/2013 -78 12345 4/3/2013 -65 12345 4/4/2013 12 12345 4/5/2013 25 12345 4/6/2013 -345 12345 4/7/2013 -450 12345 4/8/2013 -650 12345 4/9/2013 105 12345 4/10/2013 110 110000 4/1/2013 150 110000 4/2/2013 -15 110000 4/3/2013 -56 110000 4/4/2013 -35 110000 4/5/2013 -15 110000 4/6/2013 106 110000 4/7/2013 500 110000 4/8/2013 -150 110000 4/9/2013 50 110000 4/10/2013 100 55544 4/1/2013 150 55544 4/2/2013 120 55544 4/3/2013 -145 55544 4/4/2013 -250 55544 4/5/2013 15 55544 4/6/2013 20 55544 4/7/2013 40 55544 4/8/2013 50 55544 4/9/2013 -10 55544 4/10/2013 60
I am trying to get the following result from the table above. The query will apply to a transaction table with thousands of rows. Therefore, I need help creating some efficient query to calculate the following results.
Account Number Turnover time for an account to become positive 12345 3 12345 4 110000 5 110000 2 55544 3 55544 2
I am using MS SQL Server version 2008.
Yes there are zeros. and they are considered positive. I mean, when the balance turns from negative to 0 or to positive, it will be considered a turnover.
The solution provided by Fadi Hassan is the most efficient and easiest to implement. Although there is one problem with this, because when the account balance is negative at the beginning, it does not work. For example, when the balance is -110, -40, 0, 10, 90, 30, 0, -10, -20, 0. This will not work.

If anyone has a better solution, kindly help.