Hi,
I am not sure if this can be done, but I sincerely hope someone can help me out. I have a table with data like this:
counter salesrep PostDate BillDate
-001234 Adam 2006-9-23 00:00:00 2006-9-24 00:00:00
-001234 Alice 2006-9-25 00:00:00 2006-9-26 00:00:00
-001256 Danny 2006-9-23 00:00:00 2006-9-24 00:00:00
-001345 Danny 2006-9-25 00:00:00 2006-9-25 00:00:00
Counter is the unique ID for each order, and PostDate is the date the order is posted in the system. An order can be posted and billed multiple time since customer sometimes ask to change the order.
I need to write a query that counts the number of unique order posted and billed successfully by each salesrep by date. So, for example, if a sales rep posted an order today, and the order was successfully billed the next day, the sales rep gets 1 point for today's work. The challenging part in the query is that IF postdate = billdate, the order is attributed to the sales rep on the date the order is billed, not on the date the order is posted. Also, if an order is re-posted and re-billed, the sales rep only gets a point based on the re-billed date, not the first billed date. The query should return results like:
Salesrep Date # of unique order posted & billed
Alice 2006-9-25 00:00:00 1
Danny 2006-9-23 00:00:00 1
Danny 2006-9-25 00:00:00 1
Thank you in advance!
Egghi
I am not sure if this can be done, but I sincerely hope someone can help me out. I have a table with data like this:
counter salesrep PostDate BillDate
-001234 Adam 2006-9-23 00:00:00 2006-9-24 00:00:00
-001234 Alice 2006-9-25 00:00:00 2006-9-26 00:00:00
-001256 Danny 2006-9-23 00:00:00 2006-9-24 00:00:00
-001345 Danny 2006-9-25 00:00:00 2006-9-25 00:00:00
Counter is the unique ID for each order, and PostDate is the date the order is posted in the system. An order can be posted and billed multiple time since customer sometimes ask to change the order.
I need to write a query that counts the number of unique order posted and billed successfully by each salesrep by date. So, for example, if a sales rep posted an order today, and the order was successfully billed the next day, the sales rep gets 1 point for today's work. The challenging part in the query is that IF postdate = billdate, the order is attributed to the sales rep on the date the order is billed, not on the date the order is posted. Also, if an order is re-posted and re-billed, the sales rep only gets a point based on the re-billed date, not the first billed date. The query should return results like:
Salesrep Date # of unique order posted & billed
Alice 2006-9-25 00:00:00 1
Danny 2006-9-23 00:00:00 1
Danny 2006-9-25 00:00:00 1
Thank you in advance!
Egghi