The multi-statement table-valued
function is slightly more complicated
than the other two types of functions
because it uses multiple statements to
build the table that is returned to
the calling statement. Unlike the
inline table-valued function, a table
variable must be explicitly declared
and defined. The following example
shows how to implement a
multi-statement table-valued function
that populates and returns a table
variable.
USE Northwind
go
CREATE FUNCTION fx_OrdersByDateRangeAndCount
( @OrderDateStart smalldatetime,
@OrderDateEnd smalldatetime,
@OrderCount smallint )
RETURNS @OrdersByDateRange TABLE
( CustomerID nchar(5),
CompanyName nvarchar(40),
OrderCount smallint,
Ranking char(1) )
AS
BEGIN
// statements that does some processing ....
END
From the above, I guess BEGIN
and END
denotes the intent/use of multiple statements & hence it requires the table variable to be defined as shown in the code above.
from http://www.sqlteam.com/article/intro-to-user-defined-functions-updated