--创建用户定义函数
create function f_str(@A1 int, @A2 int, @A3 int, @A4 int,@A5 int,@A6 int,@A7 int)
returns int
as
begin
declare @return int
declare @table table(A int)
insert into @table
select @A1
union all select @A2
union all select @A3
union all select @A4
union all select @A5
union all select @A6
union all select @A7
select @return=avg(A) from @table where A
not in(select top 2 A from @table order by A desc)
and A not in(select min(A) from @table)
return @return
end
go
-- 调用函数来查询
select dbo.f_str(p1,p2,p3,p4,p5,p6,p7) from Project