Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql Help
Message
From
18/12/2009 14:06:34
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01439765
Message ID:
01439809
Views:
25
>>Easy :-)
>>You just need to join two table by Trucks.Overweight BETWEEN MinWeight AND Maxweight
>>And then to sum that additional column to (Trucks.Overweight - MinWeight + 1) * FineRate
>>
>>Something like this (NOT TESTED!!! and all in T-SQL, sorry)
>>
>>DECLARE @Truck TABLE (id int, overweight int);
>>insert @truck values (1,3500);
>>insert @truck values (1,2500);
>>insert @truck values (2,1500);
>>insert @truck values (2,500);
>>insert @truck values (1,500);
>>
>>DECLARE @ttt table (minweight int, maxweight int, fineamount numeric(8,4), PreviousAmount numeric(8,4));
>>insert @ttt values (   1,     1000,0.005, 0)
>>insert @ttt values (1001,     2000,0.01 ,1000*0.005)
>>insert @ttt values (2001,     3000,0.015,1000*0.005+1000*0.01)
>>insert @ttt values (3001,     4000,0.02 ,1000*0.005+1000*0.01+1000*0.015)
>>insert @ttt values (4001,     5000,0.025,1000*0.005+1000*0.01+1000*0.015+1000*0.02)
>>insert @ttt values (5001,999999999,0.03 ,1000*0.005+1000*0.01+1000*0.015+1000*0.02+1000*0.025)
>>
>>SELECT Truck.*, TestMe.PreviousAmount + (Truck.overweight-TestMe.minweight+1)*fineamount AS Something
>>FROM @Truck Truck
>>INNER JOIN @ttt TestMe ON Truck.overweight BETWEEN TestMe.minweight AND TestMe.maxweight
>>
>>
>
>The inner join condition is incorrect in this code, but the idea is good....


Why?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform