declare @year int, @month int
set @year = 2009
set @month = 06
while @year < 2011
begin
union
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) = @year
group by h.ivh_revtype1
set @year = @year + 1
end
|