?
Solved

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

Posted on 2013-01-20
4
Medium Priority
?
412 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
[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
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

770 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