天天看點

内聯表值函數FUNCTION

建立一個内聯表值函數:

1 USE TSQLFundamentals2008;
 2 IF OBJECT_ID('dbo.fn_GetCustOrders') IS NOT NULL
 3   DROP FUNCTION dbo.fn_GetCustOrders;
 4 GO
 5 CREATE FUNCTION dbo.fn_GetCustOrders
 6   (@cid AS INT) RETURNS TABLE
 7 AS
 8 RETURN
 9   SELECT orderid, custid, empid, orderdate, requireddate,
10     shippeddate, shipperid, freight, shipname, shipaddress, shipcity,
11     shipregion, shippostalcode, shipcountry
12   FROM Sales.Orders
13   WHERE custid = @cid;
14 GO      

對這個函數進行查詢:

1 SELECT orderid, custid
2 FROM dbo.fn_GetCustOrders(1) AS CO;      

轉載于:https://www.cnblogs.com/laixiancai/p/4352559.html