Something like this:
Code:
select t1.theyear, t1.themonth, t1.thecount, t2.theorders
from (
select year(orderdate) as theyear, month(orderdate) as themonth, count(*) as thecount
from orders (nolock)
where (transactionstate IN ('AUTHORIZED','CAPTURED'))
and cast(datediff(d,orderdate,shippedon) + 0 -
(DATEDIFF(wk,OrderDate,ShippedOn) + CASE WHEN DATEPART(dw,OrderDate)=1 then 1 else 0 End ) -
(DATEDIFF(wk,OrderDate,ShippedOn) + CASE WHEN DATEPART(dw,ShippedOn)=7 then 1 else 0 End ) AS int) < 2
group by year(orderdate), month(orderdate) ) as t1
join (
select year(orderdate) as theyear, month(orderdate) as themonth, count(*) as theorders
from orders (nolock)
where (transactionstate IN ('AUTHORIZED','CAPTURED'))
group by year(orderdate), month(orderdate)) as t2
on t1.theyear = t2.theyear and t1.themonth = t2.themonth
order by 1 desc, 2 desc