我有一個表如果表Else語句值函數
ProdID, ProdName, Price
我想使用,如果在表else語句值函數,使其因此,如果數量超過或等於10,我想給一個10否則沒有折扣。這是我的代碼。
Create function FDiscount (@ProdName varchar(50), @Qty int)
Returns Table
as
return
IF (@Qty >= 10)
Select ProdName, Price, @Qty as Qty, Price * @Qty as Total,
(Price * @Qty) - (Price * @Qty) /100 * 10 as Discount10
from TblProduct
Else
Select ProdName, Price, @Qty as Qty, Price * @Qty as Total
from TblProduct
Where ProdName = @ProdName
select * from FDiscount('Milk','10')
但它說:「關鍵字‘IF’附近有語法錯誤,我似乎無法找到任何解決這個。
這是節目中說什麼「有返回值的return語句不能在此上下文中使用」。 – Raksa