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?
If you have this encapsulated in a stored procedure, you could:
@@ROWCOUNT
and if it'sIF @@ROWCOUNT = 0
, then explicitly add a dummy row to that temporary tableSELECT * FROM .....
as the result of your stored procEdit: I just thought of another one...
That's the coolest SQL I've written all day.
You can user EXISTS condition if you want atleast one row like below :
The problem is you are using count(*) and other columns in single select.
query will get at least a row if it satisfies where clause.
You need to separate count(*) and columns only queries.