Here's my shot.Create Table #myTable ( ID char(2), Customer varchar(20), Pcs int, Wgt int, Cost decimal(15,2), ProDate Datetime)Insert Into #myTableSelect 'PS', 'Pollak', 25, 1001, 311.25, '1/20/2003' Union AllSelect 'PO', 'Stone', 25, 650, 610.16, '1/20/2004' Union AllSelect 'PS', 'Pollak', 25, 781, 898.77, '1/20/2005' Union AllSelect 'PO', 'Stone', 25, 512, 199.68, '1/20/2003' Union AllSelect 'PS', 'Pollak', 25, 956, 389.39, '1/20/2005' Union AllSelect 'PO', 'Stone', 25, 684, 500.00, '1/20/2005'Select * From #myTableSelect id, Customer, Cost2003, Cost2004, Cost2005, Proj2006 = Cost2005 * (case when cost2003<=0.0 then .5 else cost2004/cost2003/2 end + case when cost2004<=0.0 then .5 else cost2005/cost2004/2 end)From ( Select Id, Customer, Cost2003 = sum(case when year(proDate)=2003 then cost else 0 end), Cost2004 = sum(case when year(proDate)=2004 then cost else 0 end), Cost2005 = sum(case when year(proDate)=2005 then cost else 0 end) From #myTable Group by id, customer ) ADrop Table #myTable
Corey
Secret Service Agent: Mr. President, you're urinating on me.President Lyndon Johnson: I know I am. It's my prerogative.