-- select status,count(*) from oi group by status

--select ord.site,cat,count(*) from ord,oi,coop where ord.orno=oi.orno and ord.final=coop.cno and ortype in ('DI','RP') and
--oi.status in ('INSPECT','PSHIP','SHIPPED') and cast(oi.acted as date) between '01-01-2015' and '12-31-2015' group by ord.site,cat order by 1,2
--select ord.site,cat,count(*) from ord,oi,coop where ord.orno=oi.orno and ord.final=coop.cno and ortype in ('DI','RP') and
--oi.status in ('INSPECT','PSHIP','SHIPPED') and cast(oi.acted as date) between '01-01-2015' and '12-31-2015' group by ord.site,cat order by 1,2


select * from 
(
   select ord.site,cat,ISNULL(COUNT(*),0) XCOUNT
  from ord,oi,coop where ord.orno=oi.orno and ord.final=coop.cno and ord.ortype in ('DI','RP') and
     oi.status in ('INSPECT','PSHIP','SHIPPED') and year(oi.acted) = 2018  group by ord.site,caT
) src
pivot
(
 sum(xcount)
  for cat in ([UARS], [UFED], [STA], [UCOM], [UPRU] , [UIND], [UAID], [INT], [FGEN], [FCOM], [FPRU], [FIND])
  
) piv;