Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:08:16+00:00 2026-06-03T08:08:16+00:00

I wrote the following script that works fine in my SQL Server 2008 developer

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:08:18+00:00Added an answer on June 3, 2026 at 8:08 am

    this should help you out:

    update fc_test
       set AFS_OH = - fc2.AFS_ToProduce
      from fc_test
     -- Self join to find previous row
     inner join fc_test fc2
     -- which has lower forecastid
        on fc2.ForecastID < fc_test.ForecastID
     where fc_test.AFS_ToProduce > 0
     -- and negative afs_toproduce
       and fc2.afs_toproduce < 0
     -- and is a row immediately before
     -- ie there is no other row closer to fc_test then current fc2
       and not exists (select null 
                         from fc_test fc3
                        where fc3.forecastid > fc2.forecastid
                          and fc3.ForecastID < fc_test.ForecastID)
    

    I’m using the same table and column names as last time.

    Live test is at Sql Fiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a database using SQL Server Management Objects . I wrote the following
I wrote the following script, which generates a SyntaxError : #!/usr/bin/python print Enter the
I have an interesting problem. I wrote the following perl script to recursively loop
following is the bash script I wrote for Sqlite. #!/bin/bash sqlite3 file.db CREATE TABLE
I wrote an fsi script that worked great and wanted to compile it so
I have the following piece of code which works fine and does what it
I wrote the following script to avoid exposing the protected files to users logged
I wrote the following line to parse images from twitter profiles and it works
I wrote a small script to extract data from Oracle using Takusen: {-# LANGUAGE
I wrote a bash script that fetches lyrics from a website. The script is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.