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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

 SQL Server Forums Profile | Active Topics | Members | Search | Forum FAQ Register Now and get your question answered!
 All Forums  SQL Server 2005 Forums  Transact-SQL (2005)  SQL Query Help Reply to Topic  Printer Friendly
Author  Topic

jwlooi
Starting Member

3 Posts

 Posted - 09/10/2013 :  07:02:09 tableABCitemid char(8)conditionamt moneyamount moneyitemid conditionamt amount04400110 100.00 28.5004400110 200.00 27.0004400110 300.00 25.50I need a query to get the amount based on the conditionamt of a total purchase amt on the itemid.Example John have a total purchase amt of 105.00 which is more than conditionamt 100.00 and below 200 and below 300 the result is 28.50 as rebate bonusJohn have a total purchase amt of 250.00 which is more than conditionamt 200.00 and below 300 the result is 27.00 as rebate bonusJohn have a total purchase amt of 400.00 which is more than conditionamt 300.00 the result is 28.50 as rebate bonusThanks in advance for your help.

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
169 Posts

 Posted - 09/10/2013 :  08:29:23 declare @Amount decimal(10,2) = 301.00select distinct ( case when @Amount >= (select Conditionamt from tableABC where Conditionamt = 100.00) and @Amount <= 200 and @Amount <= 300 then '28.50' when @Amount >= (select Conditionamt from tableABC where Conditionamt = 200.00) and @Amount < 300 Then '27.00'when @Amount > (select Conditionamt from tableABC where Conditionamt = 300.00) then '28.50'else 'NULL'end) as 'Rebate Bonus'from tableABCveeranjaneyulu Edited by - VeeranjaneyuluAnnapureddy on 09/10/2013 08:36:38

jwlooi
Starting Member

3 Posts

 Posted - 09/10/2013 :  21:40:28 Hi veeranjaneyulu,Thanks for your reply.I do not want to fix the Rebate Bonus as the result return.I need to return the value from the amount in the tableABC.Maybe I did not provide you enough information.The ConditionAmt and Amount in the tableABC can be some other valuesbased on the itemid.Here is the sample with different values.itemid conditionamt amount04400110 100.00 28.5004400110 200.00 27.0004400110 300.00 25.5008800220 50.00 19.0008800220 80.00 18.0008800220 150.00 15.0008800220 200.00 14.00Thanks,looideclare @Amount decimal(10,2) = 301.00select distinct ( case when @Amount >= (select Conditionamt from tableABC where Conditionamt = 100.00) and @Amount <= 200 and @Amount <= 300 then '28.50' when @Amount >= (select Conditionamt from tableABC where Conditionamt = 200.00) and @Amount < 300 Then '27.00'when @Amount > (select Conditionamt from tableABC where Conditionamt = 300.00) then '28.50'else 'NULL'end) as 'Rebate Bonus'from tableABCveeranjaneyulu

jwlooi
Starting Member

3 Posts

 Posted - 09/11/2013 :  21:43:31 Thanks everyone of you for trying to help.I have already got the solutions that solved my problems.
Topic
 Reply to Topic  Printer Friendly Jump To: Select Forum General SQL Server Forums       New to SQL Server Programming       New to SQL Server Administration       Script Library       Data Corruption Issues       Database Design and Application Architecture SQL Server 2012 Forums       Transact-SQL (2012)       SQL Server Administration (2012)       SSIS and Import/Export (2012)       Analysis Server and Reporting Services (2012)       Replication (2012)       Availability Groups and DR (2012)       Other SQL Server 2012 Topics SQL Server 2008 Forums       Transact-SQL (2008)       SQL Server Administration (2008)       SSIS and Import/Export (2008)       High Availability (2008)       Replication (2008)       Analysis Server and Reporting Services (2008)       Other SQL Server 2008 Topics SQL Server 2005 Forums       Transact-SQL (2005)       SQL Server Administration (2005)       .NET Inside SQL Server (2005)       SSIS and Import/Export (2005)       Service Broker (2005)       Replication (2005)       High Availability (2005)       Analysis Server and Reporting Services (2005)       Express Edition and Compact Edition (2005)       Other SQL Server Topics (2005) SQL Server 2000 Forums       SQL Server Development (2000)       SQL Server Administration (2000)       Import/Export (DTS) and Replication (2000)       Transact-SQL (2000)       Analysis Services (2000)       MSDE (2000) Development Tools       ASP.NET       Reporting Services Development       Other Development Tools Site Related Forums       Site Related Discussions       Article Discussion       Poll Discussion       The Yak Corral Other Forums       SQL Server 6.5 \ SQL Server 7.0       Other Topics       MS Access       ClearTrace Support Forum Old Forums       CLOSED - General SQL Server       CLOSED - SQL Server 2005/Yukon  -------------------- Home Active Topics Frequently Asked Questions Member Information Search Page
 SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC