I have the following query:
SELECT System_Type_ID,
CASE
WHEN COUNT(DISTINCT(ship_date))=0
THEN 0
ELSE COUNT(Customer_Order_ID)/COUNT(DISTINCT(ship_date))
END TotalOrders
FROM Customer_Order
WHERE LEFT(Ship_Date,11) = LEFT(GETDATE(),11)
AND DATEPART(dw,Ship_Date) <> 7
AND Order_Status_ID NOT IN (0,9)
GROUP BY System_Type_ID
This works fine except when the day is Sunday (7) or when no orders
exist for the current day.
I include the LEFT date comparison because the time on ship_date always = 00:00:00.
I include DATEPART (dw,Ship_Date)<>7 because there may be times when
someone runs the report relying on this query on a Sunday,
credits/rebills are done on Sunday, so I can't show them as order and
we don't have a flag for a rebill.
I include Order_Status_ID NOT IN (0,9) for business reasons.
What I need: For System_Type_ID = 1 and for TotalOrders = 0 when no
orders exist for the current day or for any Sunday.
Please let me know if you need any more info. I'll be checking often
because I need this quickly (like every other problem).
Regards, Krickles |