I appreciate any help I can get. As you will probably be able to tell when I ask my question, I am a complete newbie when it comes to SQL. I just started a class in Database Design and I am already stuck.
Anyway, my question is this: why am I getting an error message when I execute my query? I hope I am providing all the necessary information. This is my SELECT statement:
SELECT ItemID, ItemPrice, DiscountAmount, Quantity, (ItemPrice * Quantity) AS [PriceTotal], (DiscountAmount * Quantity)
AS [DiscountTotal], ((ItemPrice-DiscountAmount) * Quantity) AS [ItemTotal]
FROM OrderItems
WHERE ItemTotal > 500
ORDER BY ItemTotal DESC
And this is the question asked of me:
ItemPrice.......................The ItemPrice column
DiscountAmount...........The DiscountAmount column
Quantity.........................The Quantity column
I can tell the issue is with the ItemTotal column I created in my SELECT statement, but I don't know how to fix it. I could very well be wrong, but I thought that when I declared a temporary column using the AS clause, that I could use the title of that column for the rest of the statement. I don't know how to post the database I am using on here, so I hope you don't need that. Oh, but when I execute the statement, the message says that the ItemTotal column doesn't exist. And when I comment out the WHERE clause in my statement, it works fine.
Sorry for the long winded question and I eagerly away any help I can get. Thanks!