某电器商品海关进口税征收办法,起征点为500元,超出部分按以下2级计算:
1 、超过0至150, 税率3% 。
2、 超过150元以上 ,税率10% 。
商品进口税=(商品总额-500)*税率
程序输出:编写一个函数,实现输入商品的总额,返回该商品的进口税。下面创建函数语句正确的是:( )
CREATE FUNCTION goods
( @total AS money)
RETURNS money AS
BEGIN
declare @income money
declare @tax money
select @income=@total-500
if @income<=0 set @tax=0
else begin
if(0<@income and @income<=150)
select @tax=@income*0.03
if(@income>150)
select @tax=@income*0.1
end
return @tax
END
CREATE FUNCTION goods
( @total AS money)
RETURNS money AS
BEGIN
declare @income money
declare @tax money
set @income=@total-500
if @income<=0 set @tax=0
else begin
if(0<@income and @income<=150)
set @tax=@income*0.03
if(@income>150)
set @tax=@income*0.1
end
return @tax
END
CREATE FUNCTION goods
( @total AS money)
RETURNS money AS
BEGIN
declare @income money
declare @tax money
select @income=@total-500
begin
if(0<@income and @income<=150)
select @tax=@income*0.03
if(@income>150)
select @tax=@income*0.1
end
return @tax
END
CREATE FUNCTION goods
( @total AS money)
RETURNS money AS
BEGIN
declare @income money
declare @tax money
set @income=@total-500
if @income<=0 set @tax=0
else begin
if(0<@income<=150)
set @tax=@income*0.03
if(@income>150)
set @tax=@income*0.1
end
return @tax
END
@total AS moneySQL中的自定义函数总共有三种
(1)标量函数——标量值函数
语法结构:
CREATE FUNCTION function_name(@parameter_name parameter_data_type) --(@参数名 参数的数据类型) RETURN date_type --返回返回值的数据类型
[WITH ENCRYPTION] --如果指定了 encryption 则函数被加密
[AS]
BEGIN
function_body --函数体
RETURN 表达式;
END
(2)表值函数——内联表值函数
语法结构:
CREATE FUNCTION function_name(@parameter_name parameter_data_type) --(@参数名 参数的数据类型)
RETURN table --返回一张表
[AS]
RETURN(--返回下面空白部分所写语句中查询的表)
(3)表值函数——多语句表值函数
语法结构:
create function 名称
([{@参数名称 参数类型[=默认值]}[,n]])
returns @局部变量 table(参数名 参数类型)
[with encryption]
[as]
begin
函数体
return 函数返回值
end
参考:https://blog.csdn.net/adreammaker/article/details/68071214