USE SimpleDeploy
GO

IF EXISTS (SELECT * FROM sys.objects WHERE name = 'GetTop10' AND type = 'FT')
	DROP FUNCTION GetTop10
IF EXISTS (SELECT * FROM sys.assemblies WHERE name = 'AmazonDVD')
	DROP ASSEMBLY AmazonDVD
IF OBJECTPROPERTY(object_id('actors'), 'IsUserTable') = 1
	DROP TABLE actors
GO

CREATE TABLE [Actors]
 (Actor NVarchar(100)
	CONSTRAINT ActorsPK
		PRIMARY KEY CLUSTERED)
GO

CREATE ASSEMBLY AmazonDVD 
	FROM 'C:\SYSolutions, Inc\Yukon\DecemberCTP\Projects\AmazonDVD\AmazonDVD\bin\Debug\AmazonDVD.dll' 
WITH PERMISSION_SET = UNSAFE
GO

CREATE FUNCTION GetTop10
	(@Actor nvarchar(100))
RETURNS TABLE 
([Original Release Date]	datetime,
 [Title]					nvarchar(40),
 [Amazon List Price]		smallmoney,
 [Running Time]				int,
 [Amazon Used Price]		smallmoney,
 [Used Stock]				int)
AS 
EXTERNAL NAME AmazonDVD.ActorDVD.GetTop10
GO

SELECT TOP 1 * FROM dbo.GetTop10(N'Elisabeth Shue')
GO

INSERT dbo.Actors
	VALUES(N'Tom Cruise')
INSERT dbo.Actors
	VALUES(N'Elisabeth Shue')
INSERT dbo.Actors
	VALUES(N'Jean Claude Van Damme')
INSERT dbo.Actors
	VALUES(N'Kimberly Tripp') -- not a real actor... :)
INSERT dbo.Actors
	VALUES(N'NotARealName') -- not a real name...
GO

SELECT * 
FROM dbo.Actors AS a
  CROSS APPLY dbo.GetTop10(a.Actor)
GO

SELECT * 
FROM dbo.Actors AS a
  OUTER APPLY dbo.GetTop10(a.Actor)
GO

-- The prices are correct at the time of the query and are NOT 
-- guaranteed by me or Amazon :)~

-- OK - the real disclaimer - as per Amazon Web Services Agreement:
-----------------------------------------------------------
--- Price is accurate as of the date/time indicated.	---
--- Prices and product availability are subject to		---
--- change. Any price displayed on the Amazon website	---
--- at the time of purchase will govern the sale of		---
--- this product.										---
-----------------------------------------------------------