***************************************
USE [Northwind]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create FUNCTION [dbo].[fnTops]
(@Top int, @CategoryID int)
RETURNS TABLE
AS
RETURN
SELECT TOP(@Top) ProductName, UnitPrice
FROM dbo.Products
WHERE CategoryID=@CategoryID
ORDER BY UnitPrice DESC;
*****************************************
If I do:
select * from [dbo].[fnTops](3,5)
It returns 3 rows fine.
If I do:
SELECT CategoryID, CategoryName, ProductName, UnitPrice
FROM dbo.Categories C CROSS APPLY
dbo.fnTops(2, C.CategoryID) P
ORDER BY C.CategoryID, ProductName
I get:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'C'.
But if I change C.CategoryID to 3, it works fine.
What is wrong here?
Thanks,
Tom
--
Plamen Ratchev
http://www.SQLStudio.com
Thanks,
Tom
"Plamen Ratchev" <Pla...@SQLStudio.com> wrote in message
news:rbs886tr0geva4oah...@4ax.com...