创建一个内联表值函数:
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