我使用 CROSS APPLY 参数编写了以下脚本,该脚本在我的 SQL Server 2008 开发人员数据库中运行良好,但它不适用于拥有 SQL Server 2000 数据库并且不想更改 SSMS 中的兼容性设置的客户端。
有人可以建议一种方法来转换下面的脚本以免使用 CROSS APPLY 参数吗?谢谢!
DECLARE @Flag INT
SET @Flag = 1
WHILE (@Flag < (SELECT TOP 1 (COUNT(CUSTOMERPN)) AS COUNTCUST FROM FC_Nestle
GROUP BY CustomerPN
ORDER BY COUNTCUST DESC))
BEGIN
--UPDATE AFS_TOPRODUCE COUNTS
UPDATE FC_Nestle
SET AFS_ToProduce = CustReqQty - AFS_OH
--UPDATE SUBSEQUENT AFS_OH INVENTORY COUNTS
update FC_Nestle
set AFS_OH = - fc2.AFS_ToProduce
from FC_Nestle
CROSS APPLY
(
select fc2.AFS_ToProduce
from
(
select top 1
fc2.AFS_ToProduce
from FC_Nestle fc2
where fc2.ForecastID < FC_Nestle.ForecastID and fc2.CustomerPN = FC_Nestle.CustomerPN
order by fc2.ForecastID desc
) fc2
where fc2.AFS_ToProduce < 0
) fc2
where FC_Nestle.AFS_ToProduce > 0
SET @Flag = @Flag + 1
END