为什么我不能得到价值0
列时@processdate date = null
或周日(该交易不是发生在星期日)列值没有显示出来
这是我原来的查询,只有给我的价值观当@processdate
声明为不是星期日或空 我需要它给我看一个0表时@processdate= null
或周日
alter procedure USP_CTG_VolumeReport
@processdate date = '1/8/2017'
as
declare @date date = coalesce(@processdate, cast(getdate() as date))
select 'apa' as Source,
cast(AccountID_AssignDT as date)as 'Date',
count(*) as Total_Count
from apa_2000
where
cast(AccountID_AssignDT as date) = @date
group by
cast(AccountID_AssignDT as date)
我应该能够得到适当的表中的任何星期表与子查询,但由于某种原因 - 它不工作 以下是我的子查询是给我相同的结果,我以前的查询
select
'apa' as Source,
cast(AccountID_AssignDT as date)as 'Date',
isnull((select count(*)
from apa_2000
where cast(AccountID_AssignDT as date) = @date)
, 0) as Total_Count
from apa_2000
where
cast(AccountID_AssignDT as date) = @date
group by
cast(AccountID_AssignDT as date)
你能表现出一定的样本数据,你所得到的结果,什么你期待? –
出处/日期/ TOTAL_COUNT 是我的结果,还有那些列在下面没有值时processdate = null或例如“2017年1月8日”(星期日)....我想看到“0” TOTAL_COUNT下如果processdate为空或任何一天,这将是周日(基本上任何时候,当没有什么可以指望我想看看0 TOTAL_COUNT下,而不是一个空行 – D26
你总是在一个日期路过?如果是这样,这将使它更容易解决。 –