declare @year int, @month int
set @yearFrom = 2009
set @yearTo = 2011
set @month = 06
begin
select
h.ivh_revtype1,
@month, @year,
'Line Haul',
(select sum(i.ivd_charge))
from invoicedetail as i inner join invoiceheader as h on i.ivh_hdrnumber = h.ivh_hdrnumber
where month(h.ivh_deliverydate) = 06 and i.cht_itemcode like 'LH%' and
year(h.ivh_deliverydate) between @yearFrom and @yearTo
group by h.ivh_revtype1
end
|