最近在自学sql05,就装了个08进行学习。
在Northwind数据库中,
新建一个表值函数
USE [Northwind]
GO
/****** Object:  UserDefinedFunction [dbo].[fn_top_products]    Script Date: 04/27/2010 09:36:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[fn_top_products]
(@supid as INT,@catid as INT,@n as INT)
RETURNs TABLE
AS
RETURN SELECT TOP(@n) WITH TIES productID,productname,unitprice
FROM dbo.Products
WHERE supplierID=@supid AND categoryID=@catid
ORDER BY unitprice DESC
使用如下cross apply语句报错SELECT s.SupplierID,
s.CompanyName,
p.productID,
p.productName,
p.UnitPrice
FROM dbo.Suppliers as s
 CROSS APPLY dbo.fn_top_products(s.SupplierID,1,2)as  p如果把fn_top_products(s.SupplierID,1,2)换成fn_top_products(1,1,2)就能正确查询
请大家帮忙看看啊