I wrote the following script that works fine in my SQL Server 2008 developer database using the CROSS APPLY parameter but it will not work for the client who has a SQL Server 2000 database and does not want to change the compatibility setting in SSMS.
Can someone suggest a way to convert my script below so as not to use the CROSS APPLY parameter? Thanks!
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
this should help you out:
I’m using the same table and column names as last time.
Live test is at Sql Fiddle.