今天脑子不好使,函数返回表变量时出了个问题。
经过调查。发现函数没有错,是调用函数的语句错啦。
在网上找到个例子。写在这里共勉。
Code
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
SELECT * FROM LargeOrderShippers( 0 )