Google Answers Logo
View Question
 
Q: TSQL: Return set value when where clause causes no return (not null blank) ( No Answer,   0 Comments )
Question  
Subject: TSQL: Return set value when where clause causes no return (not null blank)
Category: Computers > Programming
Asked by: krickles-ga
List Price: $50.00
Posted: 09 Jan 2005 19:18 PST
Expires: 10 Jan 2005 17:46 PST
Question ID: 454767
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
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy