Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stored procedure to calculate Sales discounts across the board

Posted on 2004-09-27
8
Medium Priority
?
462 Views
Last Modified: 2006-11-17
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
Comment
Question by:zachvaldez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 19

Accepted Solution

by:
Melih SARICA earned 700 total points
ID: 12166720
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
 
LVL 15

Assisted Solution

by:mcmonap
mcmonap earned 300 total points
ID: 12167126
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
 

Author Comment

by:zachvaldez
ID: 12171981
How about adding the start and enddate of the discounts? Do a parameter needed?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 19

Expert Comment

by:Melih SARICA
ID: 12176793
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
 

Author Comment

by:zachvaldez
ID: 12179703
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
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 12179973
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
 

Author Comment

by:zachvaldez
ID: 12184419
confuse which is PK and Index.. need step through please
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 12187724
ok..

PublisherID and DiscountStartDate  must be PK ( Clustered First Index )

PublisherID and DiscountEndDate  must be secondary Index



0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question