1、多语句表值函数

-- =============================================  
-- Author:      <Author,,Name>  
-- Create date: <Create Date,,>  
-- Description: <Description,,>  
-- =============================================  
CREATE FUNCTION 表值函数名 
(     
    @传入参数1,
		@传入参数2
)  
RETURNS TABLE   
AS  
RETURN   
(  
    --需要返回的资料表
    SELECT * from 表  where field1= @传入参数1 and field2=@传入参数2
)  
GO  

2、内联表值函数

-- =============================================  
-- Author:      <Author,,Name>  
-- Create date: <Create Date,,>  
-- Description: <Description,,>  
-- =============================================  
CREATE FUNCTION 表值函数名  
(  
   @传入参数1,
	 @传入参数2
)  
RETURNS   @返回表 TABLE   
(  
   返回表字段1   字段类型,
   返回表字段2   字段类型,
   返回表字段3   字段类型
	 ......
)  
AS  
BEGIN  
   insert into  @返回表 select field3,field4,field5 from 表 
			 where field1=@传入参数1 and field2=@传入参数

    RETURN   
END  
GO