如何开发不接受任何值的表格UDF并计算每个employee_id的佣金。 我有一张叫做广告活动的表格
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'))
)
这是我试图调用的功能
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
我在这里试试
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
)
答案 0 :(得分:0)
您不需要将参数传递给外部函数
Create Function TabularCommission()
Returns table
As
Return
(
Select Employee_ID
,dbo.OfferCommission(Offer_value, Offer_date) as Commission
from Campaign_Offer
where Acceptance_status = 'yes'
)