I have a table
ProdID, ProdName, Price
I want to use if else statement in table valued function to make it so that if Qty is over or equal 10, I would give a 10 percent discount else no discount. This is my code.
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')
But it said "Incorrect syntax near the keyword 'IF', I can't seem to find any solution to this.