|
mayurcreation
Starting Member
16 Posts |
Posted - 2007-09-13 : 10:03:54
|
| hiI have table Salesperson with following columns:Id, Name, Year, Target, Actual, Perc_Achived1, AA, 2007, 10000, '', ''2, BB, 2007, 20000, '', ''3, CC, 2007, 10000, '', ''4, DD, 2007, 30000, '', ''I hava another table MarketValue with following columns:account, value, salesperson, open_dtxx, 2000, AA/BB, 02/25/2007yy, 5000, CC/AA, 03/30/2003zz, 6000, BB/DD, 8/1/2004mm, 3000, AA, 9/1/2007nn, 2000, CC, 5/5/2006yy, 7000, CC/AA, 03/30/2007zz, 6000, BB/DD, 8/1/2007............I have percentage slipt between salespersons in different table SalespersonDetail :cust3, salesperson, perc_accountAA/BB, aa, 25AA/BB, bb, 75BB/DD, bb, 30BB/DD, dd, 70CC/AA, aa, 50CC/AA, cc, 50AA, AA, 100BB, BB, 100CC, CC, 100DD, DD, 100I need to (sum the value of account) as Actual with sales person perc_account where open_dt is in 2007 for all sales person and update Salesperson table with Actual and Perc_Achived.I have write down following query which give me result.select s.salesperson as Name, sum ((m.value * s.perc_of_account)/100) as Actualfrom marketvalue m , salespersondetail swhere m.salesperson_id = s.cust3and DATEPART(year, [open_dt]) = '2007' group by s.salespersonResult------Name ActualAA 107262115.73000000BB 62198250.87000000CC 75329154.53000000DD 212301243.82000000I dont know now how to update this result into Salesperson table. Name, Actual.Any help will be really appreciated... |
|