Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sql Help
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01439765
Message ID:
01439809
Vues:
24
>>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform