I don't know why I'm receiving different counts:
This query gives me a count of 16 records that are over 300
Select p.doc,
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 250 THEN clms END) AS [250],
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 300 THEN clms END) AS [300],
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 350 THEN clms END) AS [350],
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 400 THEN clms END) AS [400]
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
join natdocfile n
on n.doc = p.fo
where d.typecode='7' and d.reportsto='F03' and p.doc ='s09'
Group By p.doc
Now this query will list the clms and it gives me 17 clms.
Select distinct p.CLMS, p.DOC,
p.Reg,
n.RegionAcronym,
p.FO,
Age = Datediff(day,max(p.filedate), getdate()),
FileDate = max(FileDate),
o.mailingaddressstate as DDS,
o.ddsofficecode as DDSCode,
Min(ddsrcpt) AS DDSReceipt,
DDSAge = Datediff(day,min(p.ddsrcpt), getdate()),
Title = case when min(p.Title) <> max(p.Title) then 'Concurr' else min(p.Title) end
From pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
join natdocfile n
on n.doc = p.fo
join offices.dbo.doorsinfo o
on o.officecode = p.fo
where p.doc ='s09'--@doc
AND ( Datediff(DAY, filedate, Getdate()) > 300 )
Group By p.fo, p.Reg, n.regionacronym,p.DOC, p.CLMS, o.ddsofficecode,
o.mailingaddressstate
order by clms
Can you see what I am doing wrong in the first query to get one less number? Do I have it set up right to get the counts?
This query gives me a count of 16 records that are over 300
Select p.doc,
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 250 THEN clms END) AS [250],
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 300 THEN clms END) AS [300],
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 350 THEN clms END) AS [350],
COUNT(distinct CASE WHEN Datediff(DAY, filedate, Getdate()) > 400 THEN clms END) AS [400]
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
join natdocfile n
on n.doc = p.fo
where d.typecode='7' and d.reportsto='F03' and p.doc ='s09'
Group By p.doc
Now this query will list the clms and it gives me 17 clms.
Select distinct p.CLMS, p.DOC,
p.Reg,
n.RegionAcronym,
p.FO,
Age = Datediff(day,max(p.filedate), getdate()),
FileDate = max(FileDate),
o.mailingaddressstate as DDS,
o.ddsofficecode as DDSCode,
Min(ddsrcpt) AS DDSReceipt,
DDSAge = Datediff(day,min(p.ddsrcpt), getdate()),
Title = case when min(p.Title) <> max(p.Title) then 'Concurr' else min(p.Title) end
From pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
join natdocfile n
on n.doc = p.fo
join offices.dbo.doorsinfo o
on o.officecode = p.fo
where p.doc ='s09'--@doc
AND ( Datediff(DAY, filedate, Getdate()) > 300 )
Group By p.fo, p.Reg, n.regionacronym,p.DOC, p.CLMS, o.ddsofficecode,
o.mailingaddressstate
order by clms
Can you see what I am doing wrong in the first query to get one less number? Do I have it set up right to get the counts?