The way this stored procdure is set up it produces this:
doc cnt
S09 1
S09 2
S09 9
S09 51
S0B 1
S0B 4
S0B 16
S0B 57
How do I change it to give me results as this?
Doc 250 300 350 400
S09 1 2 9 51
S0B 1 4 16 57
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
Group By
doc, clms ) AS T
GROUP BY
doc
union
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
And (Datediff(Day, filedate, Getdate()) > 300)
And (Datediff(Day, filedate, Getdate()) < 351)
Group By
doc, clms ) AS T
GROUP BY
doc
union
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
And (Datediff(Day, filedate, Getdate()) > 350)
And (Datediff(Day, filedate, Getdate()) < 400)
Group By
doc, clms ) AS T
GROUP BY
doc
union
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
And (Datediff(Day, filedate, Getdate()) > 400)
Group By
doc, clms ) AS T
GROUP BY
doc
doc cnt
S09 1
S09 2
S09 9
S09 51
S0B 1
S0B 4
S0B 16
S0B 57
How do I change it to give me results as this?
Doc 250 300 350 400
S09 1 2 9 51
S0B 1 4 16 57
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
Group By
doc, clms ) AS T
GROUP BY
doc
union
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
And (Datediff(Day, filedate, Getdate()) > 300)
And (Datediff(Day, filedate, Getdate()) < 351)
Group By
doc, clms ) AS T
GROUP BY
doc
union
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
And (Datediff(Day, filedate, Getdate()) > 350)
And (Datediff(Day, filedate, Getdate()) < 400)
Group By
doc, clms ) AS T
GROUP BY
doc
union
SELECT
doc,
COUNT(*) AS cnt
FROM
(
Select
doc
FROM pendingdds p
join Offices.dbfficeCodes d
on d.officecode = p.doc
where d.typecode='7' and d.reportsto='F03'
And (Datediff(Day, filedate, Getdate()) > 400)
Group By
doc, clms ) AS T
GROUP BY
doc