|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Please help with update in this scenarioPlant Month Year Amount So take an example of one scenario: Plant Month Year Amount =================== ABC,1, 2005, 2000 ABC,2, 2005, 1000 ABC,3, 2005, 1000 ABC,4, 2005, 1000 ABC,5, 2005, 1000 ABC,6, 2005, 1000 ABC,7, 2005, 1000 ABC,8, 2005, 1000 ABC,9, 2005, 1000 ABC,10, 2005, 2000 ABC,11, 2005, 2000 ABC,12, 2005, 2000 So when I look at the TotalAmount for 2005 for Plant ABC it is $16000 Now the users want to change the total amount for 2005 to 25000 and want the amount to be distributed accordingly to current months with the same weightage they have now. Please help how I can do this. Thanks Karen Try:
declare @t table ( Plant char (3) not null , [Month] tinyint not null , [Year] smallint not null , amount money not null ) insert @t values ('ABC', 1, 2005, 2000) insert @t values ('ABC', 2, 2005, 1000) insert @t values ('ABC', 3, 2005, 1000) insert @t values ('ABC', 4, 2005, 1000) insert @t values ('ABC', 5, 2005, 1000) insert @t values ('ABC', 6, 2005, 1000) insert @t values ('ABC', 7, 2005, 1000) insert @t values ('ABC', 8, 2005, 1000) insert @t values ('ABC', 9, 2005, 1000) insert @t values ('ABC', 10, 2005, 2000) insert @t values ('ABC', 11, 2005, 2000) insert @t values ('ABC', 12, 2005, 2000) update t1 set Amount = 25000.00 / (select sum (t2.Amount) from @t t2 where t2.Plant = t1.Plant ) * Amount from @t t1 select * from @t select sum (Amount) from @t -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA SQL Server MVP Columnist, SQL Server Professional Toronto, ON Canada www.pinpub.com .. "KarenM" <karenmiddl***@yahoo.com> wrote in message I have a table - AccountBalancesBudget which as the following columns:news:1141478782.695592.238770@t39g2000cwt.googlegroups.com... Plant Month Year Amount So take an example of one scenario: Plant Month Year Amount =================== ABC,1, 2005, 2000 ABC,2, 2005, 1000 ABC,3, 2005, 1000 ABC,4, 2005, 1000 ABC,5, 2005, 1000 ABC,6, 2005, 1000 ABC,7, 2005, 1000 ABC,8, 2005, 1000 ABC,9, 2005, 1000 ABC,10, 2005, 2000 ABC,11, 2005, 2000 ABC,12, 2005, 2000 So when I look at the TotalAmount for 2005 for Plant ABC it is $16000 Now the users want to change the total amount for 2005 to 25000 and want the amount to be distributed accordingly to current months with the same weightage they have now. Please help how I can do this. Thanks Karen |
|||||||||||||||||||||||