Hàm trả về một bảng

VD1:
//tạo một hàm select các mẫu tin từ table employees
create function SelectEmployees()
returns table
as
    return  (select 
         from Employees)

//Thực thi hàm
select *
from dbo.SelectEmployees() 


VD2:


ALTER FUNCTION [dbo].[getDayListToYesterday]
(
-- Add the parameters for the function here


)
RETURNS @tblDays TABLE
(
TheDay datetime
)
as
begin
DECLARE @firstDay datetime
SET @firstDay = '2006-07-01'
WHILE (@firstDay < dateadd(dd,-1,getdate() ))
BEGIN
INSERT INTO @tblDays (TheDay) VALUES(@firstDay)
SET @firstDay = dateadd(dd, 1,@firstDay)
END
RETURN  
end