I have two tables: CustomerOrder and OrderItem.
CustomerOrder has these columns: ID, CustomerId, DateOrdered, IsCreditCardPayment.
OrderItem has these columns: OrderId(FK from CustomerOrder), ProductId, Quantity, Price.
What I need to do is calculate the amount of the provision the bank takes from my business when my customers pay with a credit card. The provision is 2%.
My question is how to save the ID's in an array of those orders paid by a credit card and then tell SQL Server to only multiply the quantity and price of the order items that have that same ID from the array?
So far I have this blob:
SELECT ID FROM CustomerOrder
WHERE DateOrdered BETWEEN '2000-01-01' AND '2000-02-01'
IF( ? )
BEGIN
SELECT ID FROM CustomerOrder
WHERE IsCreditCardPayment = 1
END
FROM CustomerOrder
I am using:
Sql Server 14.0.17230.0