[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2013-01-20
4
Medium Priority
?
418 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
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…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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