Solved

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

Posted on 2013-01-20
4
396 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
ID: 38798812
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
ID: 38798880
try using  this after the number + CHAR(37) that is ascii of % character
0
 

Author Comment

by:ocdc
ID: 38799140
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
ID: 38799575
thanks.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored procedure 4 38
CROSS APPLY 4 61
kill process lock Sql server 9 75
Replication failure 1 22
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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