![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
hi all, how ca put multiple statmwnts in sum(case statment? like if i have 4 regions, and 1 product, if for each region the transport fee is different, in a sum case how can that be done, is there any " nested if statment". i tried this and of course this is not the correct result: SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'East' then(salpmt_1.amount*0.150 + salpmt_1.amount) else 0 end)AS"Base", SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'West' then(salpmt_1.amount*0.170 + salpmt_1.amount) else 0 end)AS"Base", but this leads to 2 Base the one near the other, while what i need is : if base and east = x, if base and west = y, if base and north = z ..... else 0 end. how could that be done please? |
#3
| |||
| |||
|
|
hi all, how ca put multiple statmwnts in sum(case statment? like if i have 4 regions, and 1 product, if for each region the transport fee is different, in a sum case how can that be done, is there any " nested if statment". i tried this and of course this is not the correct result: SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'East' then(salpmt_1.amount*0.150 + salpmt_1.amount) else 0 end)AS"Base", SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'West' then(salpmt_1.amount*0.170 + salpmt_1.amount) else 0 end)AS"Base", but this leads to 2 Base the one near the other, while what i need is : if base and east = x, if base and west = y, if base and north = z ..... else 0 end. how could that be done please? |
#4
| |||
| |||
|
|
hi all, how ca put multiple statmwnts in sum(case statment? like if i have 4 regions, and 1 product, if for each region the transport fee is different, in a sum case how can that be done, is there any " nested if statment". i tried this and of course this is not the correct result: SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'East' then(salpmt_1.amount*0.150 + salpmt_1.amount) else 0 end)AS"Base", SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'West' then(salpmt_1.amount*0.170 + salpmt_1.amount) else 0 end)AS"Base", but this leads to 2 Base the one near the other, while what i need is : if base and east = x, if base and west = y, if base and north = z ..... else 0 end. how could that be done please? |
#5
| |||
| |||
|
|
hi all, how ca put multiple statmwnts in sum(case statment? like if i have 4 regions, and 1 product, if for each region the transport fee is different, in a sum case how can that be done, is there any " nested if statment". i tried this and of course this is not the correct result: SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'East' then(salpmt_1.amount*0.150 + salpmt_1.amount) else 0 end)AS"Base", SUM(CASE WHEN prod_1.category = 'Base' AND CUST_1.REGION = 'West' then(salpmt_1.amount*0.170 + salpmt_1.amount) else 0 end)AS"Base", but this leads to 2 Base the one near the other, while what i need is : if base and east = x, if base and west = y, if base and north = z ..... else 0 end. how could that be done please? |
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
#10
| |||
| |||
|
|
Thank you Mr. D.A. Morgan i am sorry, i didnt make my self clear, it was my fault , the way i wrote the procedure; i meant to say : i.e. if ('base' and 'east') --> 1.5%, if ('base' and 'west') --> 2.2%, if ('base' and 'north')--> 0.95% ..... else 0 end. and so on so forth, than add % s under 'base' to get the final amount paid for carrying it, since the fee is a percentage of the sales. the reason i want to use case is because i thought it might do my job since i wanted to do the math of all these percentages and i thought that sum of case would be a good approach. |
![]() |
| Thread Tools | |
| Display Modes | |
| |