Solved

SQL question - showing 'Total Discount Value'   as percenteges in the column.

Posted on 2013-01-20
4
387 Views
Last Modified: 2013-01-20
My quey works fine.  I just need to show 'Total Discount Value' as percenteges in the 'Total Discount Value'  column  instead value.  Like 5% for the items >=10  and  2% for the items.   If this is not clear, I attached a file for an example.

SELECT ORDERS.orderid,
       INVENTORY.partid,
       Inventory.description,
       ORDERITEMS.qty,
       Inventory.price AS 'Unit Price',
       (OrderItems.qty * Inventory.price) AS 'Total Original Price',
       (OrderItems.qty * Inventory.price *
                         CASE
                           WHEN OrderItems.qty >= 10 THEN 0.05
                           when orderItems.qty < 10 Then 0.02
                         END) AS 'Total Discount Value',
       
       OrderItems.qty * Inventory.price - (OrderItems.qty * Inventory.price *
                          CASE
                               WHEN OrderItems.qty >= 10 THEN 0.05
                               when OrderItems.qty < 10 THEN 0.02
                               else 0
                          END) AS 'Final Cost'
  FROM orders, inventory, orderitems
 WHERE ORDERS.ORDERID = ORDERITEMS.ORDERID
 AND ORDERITEMS.qty >=5
   AND ORDERITEMS.PARTID = INVENTORY.PARTID
example.doc
0
Comment
Question by:ocdc
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 500 total points
Comment Utility
I'm not sure, but try this: I added a column which maybe is what you want.

SELECT ORDERS.orderid,
       INVENTORY.partid,
       Inventory.description,
       ORDERITEMS.qty,
       Inventory.price AS 'Unit Price',
       (OrderItems.qty * Inventory.price) AS 'Total Original Price',
       (OrderItems.qty * Inventory.price *
                         CASE
                           WHEN OrderItems.qty >= 10 THEN 0.05
                           when orderItems.qty < 10 Then 0.02
                         END) AS 'Total Discount Value',
       CASE
                           WHEN OrderItems.qty >= 10 THEN 0.05
                           when orderItems.qty < 10 Then 0.02
                         END) AS 'Total Discount Percentage',
       OrderItems.qty * Inventory.price - (OrderItems.qty * Inventory.price *
                          CASE
                               WHEN OrderItems.qty >= 10 THEN 0.05
                               when OrderItems.qty < 10 THEN 0.02
                               else 0
                          END) AS 'Final Cost'
  FROM orders, inventory, orderitems
 WHERE ORDERS.ORDERID = ORDERITEMS.ORDERID
 AND ORDERITEMS.qty >=5
   AND ORDERITEMS.PARTID = INVENTORY.PARTID 

Open in new window

0
 
LVL 5

Expert Comment

by:Rinil
Comment Utility
try using  this after the number + CHAR(37) that is ascii of % character
0
 

Author Comment

by:ocdc
Comment Utility
I am trying to  modify this code:  
CASE                  WHEN OrderItems.qty >= 10 THEN 0.05
                           when orderItems.qty < 10 Then 0.02
                         END) AS 'Total Discount Value',

to include:

STR((CASE  WHEN Orderitems.qty BETWEEN 5 AND  9 THEN '2%'
                    WHEN  Orderitems.qty >= 10  THEN '5%'  
                    END) AS CHAR(5))   AS  'Total Discount Value'   but this one give an error.

so that  'Total Discount Value' would look like the one in the attached file.    Also, need to format Final Cost column so that it will also look like the one in the attached file as well.  

 Thank you.
example2.doc
0
 

Author Closing Comment

by:ocdc
Comment Utility
thanks.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

12 Experts available now in Live!

Get 1:1 Help Now