I’m building a commission report that needs to include custom shipping rates if they are present in the order. Below I have two tables joined. If OrderDetails.Custom contains 'Freight' or 'Overnight' I need it to display 'OrderDetails.CustomPrice'.
If OrderDetails.Custom does not contain 'Freight' or 'Overnight' I need it to leave OrderDetails.CustomPrice blank but still display all the other fields as long as the WHERE clause is met.
Any help is greatly appreciated!
SELECT Orders.OrderDate, Orders.OrderID, Orders.PaymentAmount,
Orders.Shipping, OrderDetails.Custom, OrderDetails.CustomPrice
FROM Orders
JOIN OrderDetails
ON OrderDetails.OrderID = Orders.OrderID
WHERE OrderDate BETWEEN '04/01/12 00:00:01'
AND '04/30/12 11:59:59'
AND SalesRep_CustomerID = '21140';
You can achieve what you want with a case statement :