Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
lauren_e
Starting Member
1 Post |
Posted - 2014-02-11 : 09:33:05
|
I am developing a report to pull information out of a database using the Visual Studio Business Intellegence Studio.I have a query to count the number of rows in a specific date range, however, if there are no records in the date range it does not display anything at all but I need it to display 0.This is the query:SELECT COUNT(OpportunityId) AS NoSalesWonFROM OpportunityBaseWHERE (CreatedOn BETWEEN CAST(DATEADD(dd, - 7, GETDATE()) AS DATE) AND CAST(DATEADD(dd, 0, GETDATE()) AS DATE))GROUP BY StatusCodeHAVING (StatusCode = 1)UNION ALLSELECT 0 AS Expr1WHERE (NOT EXISTS (SELECT OpportunityId FROM OpportunityBase AS OpportunityBase_1 WHERE (StatusCode = 2)))This returns a value of 0 if there are no records counted - Great :DHowever, if there are records counted it display the number of records as well as a 0 in the row underneath which I don't want. Is there anyway to stop this happening? |
|
hbadministrator
Posting Yak Master
120 Posts |
Posted - 2014-02-20 : 14:48:56
|
SELECT COUNT(OpportunityId) AS NoSalesWonFROM OpportunityBaseWHERE ISNULL((CreatedOn BETWEEN CAST(DATEADD(dd, - 7, GETDATE()) AS DATE) AND CAST(DATEADD(dd, 0, GETDATE()),0) AS DATE))GROUP BY StatusCodeHAVING (StatusCode = 1) |
|
|
|
|
|