Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 2nd, 2005, 02:09 PM
matt12511's Avatar
matt12511 matt12511 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 36 matt12511 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 15 sec
Reputation Power: 5
SQL Query

Hello,

Hopefully someone can help me with this query.

Here are the tables:

BasketItem:
idBasket - PK for each order/basket
idBasketItem - PK for this table/each item in a specific basket
idProduct - PK for each product
intPrice - Price charged
intQuantity - quantity ordered
(more unimportant fields)

Products:
idProduct - PK for each Product
intPrice - Regular price for the product
intSalesAllowed - A 1 stored here means "Yes Sales are allowed"
idProductType - PK for the product type (i.e. posters, banners, etc.)
(more unimportant fields)

TypeDiscount:
idProductType - PK for the product type (posters, banners, etc.)
intMinQuantity - Minimum Qty ordered to qualify
intSalesAmount - Amount discounted
intSalesPercent - Percent discounted
chrPromoCode - does it require a promotion code? (no in this case)
(more unimportant fields)

Ok, I need to take an order (idBasket) and find out if they qualify for a Type Discount (Order 25 posters and save 25%...). So I need to create a stored procedure that will take idBasket and find all the idBasketItems and add up the quantities of each product type in the basket and check that number against the Minimum Qty qaulifier (intMinQuantity) and return the sales amount and percent (intSalesAmount/intSalesPercent) if it qualifies.

Here is what I have so far but this is my first real big SQL Query:

Code:
create procedure sp_QtyDiscountCheck
 
@idBasket int
 
AS
 
Select TypeDiscount.intSalesAmount, TypeDiscount.intSalesPercent, TypeDiscount.idProductType
From BasketItem, Products, TypeDiscount
where BasketItem.idBasket = @idBasket and
BasketItem.idProduct = Products.idProduct and
Products.idProductType = TypeDiscount.idProductType and
Products.intSalesAllowed = 1 and
Sum(BasketItem.intQuantity) >= TypeDiscount.intMinQuantity


Does anyone have the answer? or some direction?

Should I bring all the BasketItems into an ASP page and then write code that can check the quantities?

Thanks,

Matt

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > SQL Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT