I need to write a query where I should find the lead time/ time taken from billsent to payment received for the transactions in the given table. I have the detail explanation of table below, have a look.
Step 1: create a table "T_Account_Details" with 3 columns AccountId, TransactionDate, ActionTaken. (1001, 1002, 1003 .......)and(6/1/2013,6/4/2013,7/1/2013......)and(billsent, paymentReceived....)
Step 2: There might be some "Action taken"s that correspond to the previous "billsent"s . We should not consider these records.
step 3: Find the turn time between bill sent and payment received.
In this way I have 200 rows, for some accountid's there is only billsent and no payment recieved, and for some accountid's there is only payment received but no bill was sent, and for some accountid's the billsent date is greater than the payment recieved date.
So, for all this criteria's I need to find the turn time/lead time/time taken from billsent to payment received. As I am new to sql server, its bit complex for me, can you please help me out.