sql函数应用简单举例

阅读更多
返回某个字段
create function getrandstr(@n int)    
returns varchar(max)    
as    
begin    
  declare @k varchar(max)  
  if(@n>10)
    set @k = 100
  else
    set @k = 200  
        
return @k    
end   




返回结果集
Create function [dbo].[sf_get_customer_level_info]
(
	@customer_id int
)
returns @TempTable table (customer_id int,scores int)
as
begin
--获取客户所属积分的等级
insert into @TempTable
select customer_id ,scores  from customer(@cust_score)
return
end
GO

你可能感兴趣的:(sql)