Simple example of sql function application

return a field
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   




return result set
Create function [dbo].[sf_get_customer_level_info]
(
	@customer_id int
)
returns @TempTable table (customer_id int,scores int)
as
begin
--Get the level of points to which the customer belongs
insert into @TempTable
select customer_id ,scores  from customer(@cust_score)
return
end
GO

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326119492&siteId=291194637