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

  • SEARCH
  • Home
  • 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 7563343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:38:35+00:00 2026-05-30T13:38:35+00:00

SQL Server 2000 I have a table which lists out the months where a

  • 0

SQL Server 2000

I have a table which lists out the months where a particular product can be sold.

ProductCode     MonthNum    MonthName
XXX             1           January
XXX             2           February
YYY             1           January
YYY             3           March
YYY             5           May
ZZZ             6           June
ZZZ             7           July

I need to construct a query that would allow me to pass some parameters:

ProductCode
LatestMonthNum
LatestYear
FutureForecast

that would allow me to construct a set of data list with the total rows based on the number of FutureForecast value and the rows’ value would be beyond the passed LatestMonthNum and LatestYear parameter values.

For example, if I pass the following values to the query:

ProductCode         YYY
LatestMonthNum      5
LatestYear          2012
FutureForecast      5

I would have the data as follows:

ProductCode     MonthNum    Year
YYY             1           2013
YYY             3           2013
YYY             5           2013
YYY             1           2014
YYY             3           2014
  • 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-05-30T13:38:37+00:00Added an answer on May 30, 2026 at 1:38 pm

    I would create a table of months and years in the future (something like a numbers table):

    CREATE TABLE future (month int, year int);
    DECLARE @m int;
    SET @m = 1;
    DECLARE @y int;
    SET @y = 2000;
    WHILE (@y < 2200) -- will my brain be in a jar by now?
      BEGIN
      WHILE (@m < 13)
        BEGIN
        INSERT INTO future (month, year) VALUES (@m, @y);
        SET @m += 1;
        END
      SET @m = 1;
      SET @y += 1;
      END;
    

    Then you can join your products table with the future!

    SELECT TOP @FutureForecast
      p.ProductCode, p.MonthNum, f.[year]
    FROM Products AS p
    JOIN future AS f ON f.[month] = p.MonthNum
    WHERE 
      p.ProductCode = @ProductCode
      AND (p.MonthNum > @LatestMonthNum OR f.[year] > @LatestYear)
    ORDER BY f.[year], p.MonthNum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL 2000 server with a database (ITinventory) and a table which
I have a table on a SQL Server 2000 database, which I want copied
MS SQL Server 2000 I have a column in Table A called Name. I
I have a table in SQL Server 2000 Standard Edition called dbo.T668 (don't blame
Lets say I have a table in a sql server 2000 database called TransactionType:
I have the following table in SQL Server 2000: TABLE_NAME | COLUMN_NAME | TYPE_NAME
I have a SQL Server 2000 with a table containing an image column. How
I have a nvarchar(50) column in a SQL Server 2000 table defined as follows:
We are using SQL Server 2008. We have a table called response which has
i am using sql server 2000 .I have a table with four columns ie.

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.