Re: YTD sales showing last year's data...
OK, here's the first:
--declare @MBeg as datetime = '2017-04-01'
--declare @YBeg as datetime = '2016-07-01'
--declare @YEnd as datetime = '2017-04-30'
select c.CUSTNMBR, c.CUSTNAME, c.ITEMNMBR, c.ITEMDESC
, sum(c.M_QUANTITY) as M_QUANTITY
, sum(c.M_XTNDPRCE) as M_XTNDPRCE
, sum(c.Y_QUANTITY) as Y_QUANTITY
, sum(c.Y_XTNDPRCE) as Y_XTNDPRCE
from
(
select b.DOCDATE, b.CUSTNMBR, b.CUSTNAME, b.ITEMNMBR, b.ITEMDESC, b.ITMCLSCD, b.Y_XTNDPRCE, b.Y_QUANTITY
, case
when b.DOCDATE between @MBeg and @YEnd
then b.Y_XTNDPRCE
else 0
end as M_XTNDPRCE
, case
when b.DOCDATE between @MBeg and @YEnd
then b.Y_QUANTITY
else 0
end as M_QUANTITY
from
(
select a.SOPTYPE, a.SOPNUMBE, a.DOCDATE, a.CUSTNMBR, d.CUSTNAME, b.ITEMNMBR, c.ITEMDESC, c.ITMCLSCD
, case
when a.SOPTYPE = 3 then b.XTNDPRCE
when a.SOPTYPE = 4 then b.XTNDPRCE * -1
else 0
end as Y_XTNDPRCE
, case
when a.SOPTYPE = 3 then b.QUANTITY
when a.SOPTYPE = 4 then b.QUANTITY * -1
else 0
end as Y_QUANTITY
from SOP30200 a
join SOP30300 b on b.SOPTYPE = a.SOPTYPE and b.SOPNUMBE = a.SOPNUMBE
join IV00101 c on c.ITEMNMBR = b.ITEMNMBR
join RM00101 d on d.CUSTNMBR = a.CUSTNMBR
where a.SOPTYPE in (3,4)
and a.VOIDSTTS = 0
and a.DOCDATE between @YBeg and @YEnd
) b
) c
where c.ITMCLSCD in (@ItemClass)
group by c.CUSTNMBR, c.CUSTNAME, c.ITEMNMBR, c.ITEMDESC
order by c.CUSTNAME, c.ITEMNMBR
The second one is:
select year(getdate()) as YEAR1
union all
select YEAR1 from sy40101
order by YEAR1 desc
The third one is:
select distinct rtrim(ITMCLSCD) as ITMCLSCD from IV00101
order by ITMCLSCD
On the report itself, the qty ytd is "=Fields!Y_QUANTITY.Value" the sales ytd is "=Fields!Y_XTNDPRCE.Value"