Solved

Stored procedure to calculate Sales discounts across the board

Posted on 2004-09-27
8
431 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
2016 SQL Licensing 7 40
SQL Server 2012 - Merge Replication Issue 1 19
CPU high usage when update statistics 2 28
performance query 4 20
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

786 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