简体   繁体   中英

Correct way to pass table-valued function outputs to table-valued functions in SQL Server 2008

I'm trying to create a user-defined in-line table-valued function in SQL Server 2008 called "imageFileFromAddress":

CREATE FUNCTION [dbo].imageFileFromAddress (@address NVARCHAR(max))
RETURNS TABLE AS RETURN(
--Guts of the function.
);

The guts of the return are intended to be this, from a logical standpoint:

WITH addresses AS 
(
      SELECT * FROM [dbo].[bookPageFromAddress](@address)
)
SELECT * FROM [dbo].[imageFileFromBookPage](addresses.Book, addresses.Page)

So, bookPageFromAddress and imageFileFromBookPage are also user-defined in-line table-valued functions; I need to pass the address parameter to the former, which produces a table as output, and use its rows as arguments to the latter, taking the tables it produces, stitching them together into a single table, and returning the result. Obviously the actual code above is not valid for that, but I can't seem to wrap my head around the proper syntax. What's the proper way to do this?

SELECT *
FROM
  [dbo].bookPageFromAddress(@address) addresses
  outer apply [dbo].[imageFileFromBookPage](addresses.Book, addresses.Page) foo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM