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 2000 Forums
 SQL Server Development (2000)
 Do I need a nested dynamic query?

Author  Topic 

gheffern
Starting Member

1 Post

Posted - 2005-11-14 : 19:41:53
I have two tables: Discounts and Criteria. The Discount table has DiscountName and Amount. Criteria has several entries per each discount that have to match for a discount to be applied - CriteriaName and CriteriaValue - and the ID of the corresponding Discount. This means I need to come up with a way to process each Discount with its one or more criteria one at a time? To make it more difficult, the criteria can be different for each discount.

10% Off Web Orders
15% Off Web Orders - Las Vegas
20% Off Web Orders - Alaska - Over $299

Above are the three scenarios I am testing. Each has one entry in the Discount table. Below are the entries in the Criteria table.

10% Off Web Orders -
CriteriaName = Source / CriteriaValue = Web

15% Off Web Orders - Las Vegas
CriteriaName = Source / CriteriaValue = Web
CriteriaName = Location / CriteriaValue = Las Vegas

15% Off Web Orders - Las Vegas
CriteriaName = Source / CriteriaValue = Web
CriteriaName = Location / CriteriaValue = Alaska
CriteriaName = Total / CriteriaValue = 305

How do I get a list of Discounts and Amounts that should be applied?

Thanks for looking this over!
Gary

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-11-14 : 21:54:51
Do us a favor and post like this: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

We can then hopefully help you much quicker. We need some sample data to help you out effectively, with preferrably a good enough sample to let us do what you outlined in your original post.

You can use a CASE statement to accomplish what you need to do here. Remember that CASE statements can be used in combination with aggregation functions.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -