我需要修改以下查询以仅生成4月份的结果(需要获得总数),但不确定如何进行。我已经尝试过使用运营商之间的日期,但查询仍然显示其他月份。
select ce.CreatedDate,
msf.SentDate,
msf.CreatedDate,
cl.CreatedDate
from ClientEnrollment(nolock) ce
inner join ClientLetter(nolock) cl
on cl.ClientId = ce.ClientId
left join MailStatusFromMailVendor(nolock) msf
on msf.ClientLetterId = cl.ClientLetterId
where EnrolledById = 3
and cl.LetterTypeId = 1
and ce.CreatedDate < isnull(msf.SentDate, getdate())
and msf.SentDate is not null
--and msf.SentDate is null
and ce.IsActive = 1
and cl.IsActive = 1
order by msf.SentDate, ce.CreatedDate
答案 0 :(得分:0)
select ce.CreatedDate, msf.SentDate, msf.CreatedDate, cl.CreatedDate
from ClientEnrollment(nolock) ce
inner join ClientLetter(nolock) cl
on cl.ClientId = ce.ClientId
left join MailStatusFromMailVendor(nolock) msf o
n msf.ClientLetterId = cl.ClientLetterId
where EnrolledById = 3 and cl.LetterTypeId = 1
and ce.IsActive = 1 and cl.IsActive = 1
and ce.CreatedDate between '2019-04-01' and '2019-04-30'
and msf.SentDate between '2019-04-01' and '2019-04-30'
and msf.SentDate is not null
order by msf.SentDate, ce.CreatedDate