How do I develop a tabular UDF that does not accept any values and calculates the commission for each employee_id. I have a table called called campaign offer
Create Table Campaign_Offer
(
Offer_id integer identity(1,1) primary key,
Offer_date Date ,
Customer_id int ,
Offer_value money ,
Product_name varchar(20) ,
Acceptance_status varchar(3) ,
Employee_ID char(10) ,
Constraint CustomerID foreign key (Customer_id) references marketing_list(Id),
Constraint EmployeeID foreign key (Employee_ID) references Employee(Employee_id),
Constraint AcceptanceStatus Check (Acceptance_status in ('yes', 'no'))
)
This is the function I am trying to call
Create Function OfferCommission (@OfferValue money,@OfferDate date)
Returns money
As
Begin
RETURN @OfferValue * CHOOSE(DATEPART(QUARTER,@OfferDate), 0.1, 0.15, 0.2,
0.25)
END
I was trying it here
Create Function TabularCommission
(
@Offer_id integer,
@Offer_value money,
@Acceptance_status varchar(3)
)Returns table
As
Return
(
Select Employee_ID,dbo.OfferCommission(Offer_value, Offer_date) as
Commission from Campaign_Offer
where Acceptance_status = 'yes'
group by Employee_ID
)