Stored procedure to calculate Sales discounts across the board

I'm looking for a stored procedure to calculate Discounts for publishers by passing their  pubID.
Each discounts vary per publishers.

For Example:

All of   A  Publishers will get  10% discount this month for all thrie published books

All of B Publishers will get 20% discounts this month for all thrie published books

All of C Publishers will get 30% discounts on all their books this month.

How to build the stored procedure.
zachvaldezAsked:
Who is Participating?
 
Melih SARICAOwnerCommented:
there r 2 ways.

1. I dont Advice but itcan be solution.
   select case when publisher.type( or name if u want) = 'A' then 10
                    when publisher.type( or name if u want) = 'B' then 20
                    when publisher.type( or name if u want) = 'C' then 30
                     ...
                     ..
             end Discount

In this way u ave to write all Publisher ID's and give the exact discount for each every time Discount rate Changes

2.nd way
  Is  to create a DisCountTable
   Create Table tbl_DisCount(
       PublisherID int,
       DiscountStartDate datetime,
       DiscountEndDate   datetime,
       DisCount float )

   And in this table PublisherID and DiscountStartDate  ll be PK
   and PublisherID and DiscountEndDate   ll be the 2nd Index

Usage of this table is there must be a startdate fr each row.. But the usable discount rate depends on the end date. Null value of the DiscountEndDate shows the last discount.

when  u want to get the discount values in this table
  u must create a view like
 
Create view view_GetPublisherDiscount
as
  select top 100 Percent PublisherID,Discount where DiscountEndDate is null



Melih SARICA
0
 
mcmonapCommented:
Hi zachvaldez,

I think the procedure below will apply a discount to the price of books for a designated publisher, is this what you want?

--begin code
CREATE PROCEDURE usp_PubDiscount
      @pub_id INT
      , @discount INT = 0.
AS
UPDATE      titles
SET      price = price - (price * (@discount/100.00))
WHERE      pub_id = @pub_id
--end code
0
 
zachvaldezAuthor Commented:
How about adding the start and enddate of the discounts? Do a parameter needed?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Melih SARICAOwnerCommented:
Nope u dont need..

In most of the ERP Suits, All discounts or Price lists used like this

Just create these tables and check what i ve said..
0
 
zachvaldezAuthor Commented:
thanks ,
Please explain this part
" And in this table PublisherID and DiscountStartDate  ll be PK
   and PublisherID and DiscountEndDate   ll be the 2nd Index"

Usage of this table is there must be a startdate fr each row.. But the usable discount rate depends on the end date. Null value of the DiscountEndDate shows the last discount.

when  u want to get the discount values in this table
  u must create a view like
 
Create view view_GetPublisherDiscount
as
  select top 100 Percent PublisherID,Discount where DiscountEndDate is null
0
 
Melih SARICAOwnerCommented:
As i said be4, there ll be a table to collect Discount Rates for Each period and Publisher.

PK is the primary Key of the table  this ll be used while Joining this table and Publisher ID

Second index ll be used for getting Null value of the endDate


Is that what u want ? or more explanations ?

Melih SARICA
0
 
zachvaldezAuthor Commented:
confuse which is PK and Index.. need step through please
0
 
Melih SARICAOwnerCommented:
ok..

PublisherID and DiscountStartDate  must be PK ( Clustered First Index )

PublisherID and DiscountEndDate  must be secondary Index



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.