Δεν είναι καθόλου άστοχη η ερώτηση σου. Η απάντηση είναι οτι φυσικά και μπορείς να τη χρησιμοποιήσεις με ένα τέτοιο τρόπο. Στα books online του SQL Server 2000 υπάρχει ένα σχετικό παράδειγμα το οποίο και αντιγράφω εδω:
In a user-defined function that returns a table:
The RETURNS clause defines a local return variable name for the table returned by the function. The RETURNS clause also defines the format of the table. The scope of the local return variable name is local within the function.
The Transact-SQL statements in the function body build and insert rows into the return variable defined by the RETURNS clause.
When a RETURN statement is executed, the rows inserted into the variable are returned as the tabular output of the function. The RETURN statement cannot have an argument.
No Transact-SQL statements in a function that returns a table can return a result set directly to a user. The only information the function can return to the user is the table returned by the function.
This example creates a function in the Northwind database that returns a table:
CREATE FUNCTION LargeOrderShippers ( @FreightParm money )
RETURNS @OrderShipperTab TABLE
(
ShipperID int,
ShipperName nvarchar(80),
OrderID int,
ShippedDate datetime,
Freight money
)
AS
BEGIN
INSERT @OrderShipperTab
SELECT S.ShipperID, S.CompanyName,
O.OrderID, O.ShippedDate, O.Freight
FROM Shippers AS S INNER JOIN Orders AS O
ON S.ShipperID = O.ShipVia
WHERE O.Freight > @FreightParm
RETURN
END
In this function, the local return variable name is @OrderShipperTab. Statements in the function body insert rows into the variable @OrderShipperTab to build the table result returned by the function.
This query references the table returned by the function in its FROM clause:
SELECT *
FROM LargeOrderShippers( $500 )
Σωτήρης Φιλιππίδης
DotSee Web Services