Solved

Stored procedure to calculate Sales discounts across the board

Posted on 2004-09-27
8
428 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
  • 4
  • 3
8 Comments
 
LVL 19

Accepted Solution

by:
Melih SARICA earned 175 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 75 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now