O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CROSS APPLY

CROSS APPLY invokes a table-valued function for each row in an outer table expression, returning a unified result set out of all the results returned by the individual invocations of the table-valued function. The columns in the outer table are used as arguments to the table-valued function. If the table-valued function returns an empty set for a given outer row, that outer row is not returned in the result.

For example, the table-valued function in Listing 45.44 accepts ProductID and an integer as arguments and returns a list of the top N largest orders for that store. The number of rows returned is determined by the value passed to the second parameter. If you call this function with ProductID and a number of rows, it returns that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required