1、标量值函数

  1)、创建

create function fun_max(@x int, @y int)--标量函数
returns int as
begin
 if @x<@y
 set @x = @y
 return @x
end
declare @x int, @y int 
set @x=1
set @y=2
print 'max= ' +cast(dbo.fun_max(@x,@y) as char)

  create function fun_max(@x int, @y int)--标量函数

  returns int

   as

  begin

     if @x<@y

       set @x = @y

   return @x

  end

  2)、调用
  declare @x int, @y int 

  set @x=1

  set @y=2

  print 'max= ' +cast(dbo.fun_max(@x,@y) as char)

(注:不能出现sql语句)

2、表值函数

  1)、创建

 

  create function fun_findid(@id int)

  returns table

  as

  return select * from Renter where renterid>@id

  2)、调用

  select * from fun_findid(1001)

(注:不能定义变量)

 

 posted on 2010-05-25 14:55  H&M  阅读(437)  评论(0编辑  收藏  举报