Does anybody knows, how this cross apply works?
I need a simple example, because I have no idea what it's for!
(I can't found any good example in the net!?!?)
thanks in advance...
This is not a great example as the query would be better done with a join,
but it should help you understand the syntax:
USE AdventureWorks
GO
CREATE FUNCTION GetLineItemsForOrder(@.SalesOrderID INT)
RETURNS TABLE
AS
RETURN
(
SELECT SalesOrderDetailID
FROM Sales.SalesOrderDetail
WHERE SalesOrderID = @.SalesOrderID
)
GO
SELECT
SH.SalesOrderID,
LI.SalesOrderDetailID
FROM Sales.SalesOrderHeader SH
CROSS APPLY GetLineItemsForOrder(SH.SalesOrderID) LI
WHERE TotalDue > 20000
GO
DROP FUNCTION GetLineItemsForOrder
GO
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
"nullstring" <johannes.veit@.datapec.de> wrote in message
news:1127133941.948110.85450@.g44g2000cwa.googlegro ups.com...
> Does anybody knows, how this cross apply works?
> I need a simple example, because I have no idea what it's for!
> (I can't found any good example in the net!?!?)
>
> thanks in advance...
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment