[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

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.
0
zachvaldez
Asked:
zachvaldez
  • 4
  • 3
2 Solutions
 
Melih SARICACommented:
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Melih SARICACommented:
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 SARICACommented:
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 SARICACommented:
ok..

PublisherID and DiscountStartDate  must be PK ( Clustered First Index )

PublisherID and DiscountEndDate  must be secondary Index



0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now