Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql Help
Message
 
To
18/12/2009 13:54:32
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01439765
Message ID:
01439802
Views:
34
It is, but George not always give you a direct solution. You should think a little about it :-)
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))
insert @ttt values (   1,     1000,0.005)
insert @ttt values (1001,     2000,0.01)
insert @ttt values (2001,     3000,0.015)
insert @ttt values (3001,     4000,0.02)
insert @ttt values (4001,     5000,0.025)
insert @ttt values (5001,999999999,0.03)

Select        Truck.*,
               SUM(Case When Truck.Overweight > fine.MaxWeight
            Then (MaxWeight - MinWeight + 1) * Fineamount
                        Else (OverWeight - MinWeight + 1) * FineAmount
                        End) As Fine
From        @ttt As Fine
               Inner Join @Truck As Truck
                       On Truck.Overweight >= Fine.MinWeight
GROUP BY Truck.id, Truck.overweight
ORDER BY Truck.overweight DESC
>That is not correct. This is what the fines should be.
>
>overweight   Fine amount
>3500          $40.00
>2500          $22.50
>1500         $10.00
>500            $2.50
>
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