Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Get Subtraction remainder

Author  Topic 

LarryC74
Yak Posting Veteran

94 Posts

Posted - 2013-11-11 : 12:33:18
Good morning all,
I need just a little guidance...

I have math query that I need to do where a certain portion below 2100 is one price and anything above that number will be billed with another price.

Amt <= 2100 then .55
Amt > 2100 then 1.25

Ex: 3000
so 2100 would be billed @.55 and the remaining 900 @ 1.25


So looking at the table code below...how would I get the "over" amount for line 3.


Create Table #tmpAllosource
(
Donor# varchar(10),
Rules varchar(50),
Amt int,
Unit varchar(6),
Status varchar(11)


)

Insert Into #tmpAllosource Values ('1','Reject - Pos Sero',4500,'sq cm','Reject')
Insert Into #tmpAllosource Values ('2','Under 2100 Over 900 sq cm',1752,'sq cm','Full Bill')
Insert Into #tmpAllosource Values ('3','Under 2100 ',3542,'sq cm','Full Bill')
Insert Into #tmpAllosource Values ('4','At 2100 ',2100,'sq cm','Full Bill')
Insert Into #tmpAllosource Values ('5','900 sq cm',775,'sq cm','Full Bill')


Select a.*
, Case When (a.Amt<=2100 AND a.Amt>899 ANd a.Status <> 'Reject') Then a.Amt*.55
When (a.Amt>2100 ANd a.Status <> 'Reject') Then 2100*.55 Else 0 end as 'Under 2100 @.55/sqcm'
, '' as 'Over 2100 @1.25/sqcm'
, Case When (a.Status = 'Reject' OR a.Amt<900) Then 500
When a.Amt<=2100 AND a.Amt>899 Then a.Amt*.55 Else 0 end as Total
From #tmpAllosource a

--Drop table #tmpAllosource



any help would be greatly appreciated.
Larry







Everyday life brings me back to reality

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-11 : 12:52:45
CASE WHEN (Amt - 2100) > 0 THEN 2100 * 0.55 + (Amt - 2100)* 1.25 ELSE ....other conditions END

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

LarryC74
Yak Posting Veteran

94 Posts

Posted - 2013-11-11 : 13:05:00
THANK YOU!!!

next time I'm bringing something more challenging... ha!

Thanks again!
Larry

Everyday life brings me back to reality
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-11 : 13:11:01
No problem..You're welcome
Looking forward to see you next post!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -