Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How Can I Round the dollar about after the output of
VB
OrderItems.qty * Inventory.price - (OrderItems.qty * Inventory.price *
CASE WHEN OrderItems.qty >=10 THEN 0.05 END)


Also, How can I combine the queries below without using UNIION ALL?
SQL
SELECT ORDERS.orderid, 
INVENTORY.partid, 
Inventory.description, 
ORDERITEMS.qty,
 Inventory.price,
 (OrderItems.qty * Inventory.price) AS 'Total Original Price',
--If an order contains ten or more units of a given product,   give a 5% discount on that line item.
(OrderItems.qty * Inventory.price * 
CASE WHEN OrderItems.qty >=10 THEN 0.05 END) AS 'Total Discount Value' ,
 
 OrderItems.qty * Inventory.price - (OrderItems.qty * Inventory.price * 
CASE WHEN OrderItems.qty >=10 THEN 0.05 END)  AS 'Total_Final_Price_After_Discount' 
 
 FROM orders, inventory, orderitems
 WHERE ORDERS.ORDERID = ORDERITEMS.ORDERID  AND ORDERITEMS.PARTID = INVENTORY.PARTID
 AND ORDERITEMS.qty >=10  
 --ORDER BY ORDERS.orderid, INVENTORY.partid
 
 UNION ALL
 
 SELECT ORDERS.orderid, 
INVENTORY.partid, 
Inventory.description, 
ORDERITEMS.qty,
 Inventory.price,
 (OrderItems.qty * Inventory.price) as 'Total Original Price',


----If an order contains five or more units of a given product,  give a 2% discount for that line item. 
 (OrderItems.qty * Inventory.price * 
 CASE WHEN OrderItems.qty < 10 THEN 0.2  END) as 'Total Discounted Value',
 
  OrderItems.qty * Inventory.price - (OrderItems.qty * Inventory.price * 
CASE WHEN OrderItems.qty < 10 THEN 0.2 END)  AS 'Total_Final_Price_After_Discount'

 FROM orders, inventory, orderitems
 WHERE ORDERS.ORDERID = ORDERITEMS.ORDERID  AND ORDERITEMS.PARTID = INVENTORY.PARTID
 AND ORDERITEMS.qty BETWEEN 5  AND  9
 ORDER BY ORDERS.orderid, INVENTORY.partid
Posted
Updated 19-Jan-13 18:13pm
v2

1 solution

SQL
SELECT ORDERS.orderid,
       INVENTORY.partid,
       Inventory.description,
       ORDERITEMS.qty,
       Inventory.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 'Total_Final_Price_After_Discount'
  FROM orders, inventory, orderitems
 WHERE ORDERS.ORDERID = ORDERITEMS.ORDERID
   AND ORDERITEMS.PARTID = INVENTORY.PARTID<small></small>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900