Q:

Return a single row if no rows are found

Have this T-SQL query that we used for a CrystalReport.
SELECT COUNT(*) AS Expr1, [Date], StoreNumber
FROM   dbo.Orderp
WHERE  (OpServerNumber = 0)
GROUP BY [Date], StoreNumber

Problem occurs if no rows are valid for a specific date and store.
Is it possible to return a single row with Expr1 = 0 if the query can't find any rows I the table?

A:

You can user EXISTS condition if you want atleast one row like below : 
IF EXISTS(SELECT COUNT(*) AS Expr1, [Date], StoreNumber FROM   dbo.Orderp WHERE  (OpServerNumber = 0) GROUP BY [Date], StoreNumber)
    SELECT COUNT(*) AS Expr1, [Date], StoreNumber FROM   dbo.Orderp WHERE  (OpServerNumber = 0) GROUP BY [Date], StoreNumber
ELSE
    SELECT 0 AS Expr1, NULL [Date], 0 StoreNumber 

