Author |
Topic |
CKHong
Starting Member
13 Posts |
Posted - 2012-04-09 : 11:08:32
|
Hi,I hope someone can help me out. In my table I haveBank(column) Value(column) Expected valueBankA 100 101BankB 100 102BankA 200 202I want to get the SUM of all the bank with different charges.BankA charge 1%BankB charge 2%My query without taking consideration of the percentageSelect Sum(IsNull(TotalCharge,0)) as TotalCharge from bankwhere Bank='BankA' or Bank='BankB'How do I select the sum of the bank include the different charge?Hope someone can help me.Thanks,Brian |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-09 : 11:14:18
|
[code]SELECT Bank,SUM(Value),SUM(ExpectedValue)FROM(SELECT Bank,Value,ExpectedValue,(ExpectedValue-Value)*100/Value AS [Charge%]FROM table)tGROUP BY Bank,[Charge%][/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
CKHong
Starting Member
13 Posts |
Posted - 2012-04-09 : 11:26:55
|
Sorry.. i made the question wrong..In my table I only have this 2 columnBank(column) Value(column)BankA 100BankB 100BankA 200I need to sum up all the value based on the charges 1% and 2%Thanks for your reply visakh16. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-09 : 11:29:48
|
how do you get value of charges? from another table or user input? if user input, how will user pass multiple values? also does all charges need to applied to all banks?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
CKHong
Starting Member
13 Posts |
Posted - 2012-04-09 : 11:47:40
|
actually i'm trying to generate a report..so it is fixed..BankA will be 1% and BankB will be 2%yup.. all charges need to applied to all bankcurrently I only have 2 banks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-09 : 11:49:26
|
hmm? your statement is contradictoryyou say BankA will be 1% and BankB will be 2%then you say all charges need to applied to all bankwhat does that mean?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
CKHong
Starting Member
13 Posts |
Posted - 2012-04-09 : 11:53:08
|
hmm... sorry.. i think i misunderstand ur questionthe end result should be BankA 100 * 1.01 = 101BankB 100 * 1.02 = 102BankA 200 * 1.01 = 202Result : 101 + 102 + 202 = 405I don't know how to select the SUM by adding the charges which is fixed 1% for BankA and 2% for BankB |
 |
|
CKHong
Starting Member
13 Posts |
Posted - 2012-04-09 : 11:55:39
|
If i do it like thisSelect Sum(IsNull(TotalCharge,0)) * 1.01 as TotalCharge from bankwhere Bank='BankA' or Bank='BankB'Then it will calculate all the sum with adding 1% as the charges..I don't know how to do it so that I can calculate the sum based on 2 charges |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-09 : 12:01:12
|
you still didnt answer how you will get charge values. is it from user or table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
CKHong
Starting Member
13 Posts |
Posted - 2012-04-09 : 12:03:25
|
from user |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-09 : 12:17:26
|
please provide details on all questions asked. how do you pass multiple charge values from user as input? also how do you determine which charge needs to be associated to which bank?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
CKHong
Starting Member
13 Posts |
Posted - 2012-04-09 : 12:26:17
|
Actually the charge is fixed..i was planning to put in the charges when i wrote the query..Select Sum(IsNull(TotalCharge,0)) * 1.01 as TotalCharge from bankwhere Bank='BankA' or Bank='BankB'If i run the above query, it will set the charges 1% to all bankI would like to know if there is any query that can let me type in the query and get the total value based on BankA fixed 1% BankB fixed 2% on the sql query |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-09 : 13:29:51
|
for that you need to either input values from user in delimited format or store it in a table and use it------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|