Reputation: 2186
SELECT
Counting = ISNULL(COUNT(A.Numbers), 0),
B.Date AS DateX
From Schema1.Table A INNER JOIN Schema2.Table B
ON A.xyz=B.xyz
Where B.Date = GetDate()
Group by B.Date
Sometimes, B.Date
won’t have today’s date. I would still like to have result output with Counting = 0 and DateX = Todays date
.
How would I do that?
Thank you
EDIT by popular demand
A.Numbers = 123;456;789;012,...etc
B.Date = 2012-11-24, 2012-11-24,-212-11-24,2012-11-26
So count for 2012-11-24 = 3
and 2012-11-26 = 1
but there would be no output when I set B.Date
to 2012-11-25
I want to show Counting = 0
when B.Date = 2012-11-25
Upvotes: 0
Views: 73
Reputation: 2103
Get rid of your where clause and change your select to
Counting = (Case when B.Date = GETDATE() then ISNULL(COUNT(A.Numbers),0) else 0 end)
Upvotes: 3