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 4336380
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:47:57+00:00 2026-05-21T10:47:57+00:00

I need to rewrite this so it does not cause an overrun on my

  • 0

I need to rewrite this so it does not cause an overrun on my db. I need to rewrite it so it does not use a cursor.

Thank you.

  • 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-21T10:47:58+00:00Added an answer on May 21, 2026 at 10:47 am

    UPDATED Here’s some test data:

    CREATE TABLE #TableB(SKU INT, BeginYear INT, EndYear INT, OptionA VARCHAR(10), OptionB VARCHAR(10))
    
    INSERT INTO #TableB(SKU, BeginYear, EndYear, OptionA, OptionB)
    VALUES  (1, 1920, 1950, 'option1', 'option1'),
            (1, 1980, 2001, 'option1', 'option2'),
            (1, 1940, 1952, 'option1', 'option1'), --overlapping years
            (2, 2001, 2005, 'option1', 'option1')
    
    CREATE TABLE #TableA(SKU INT, OptionA VARCHAR(10), OptionB VARCHAR(10), Years INT)
    

    Then you can try a recursive CTE:

    ;WITH CTE AS
    (
        SELECT DISTINCT SKU, BeginYear, EndYear, OptionA, OptionB
        FROM #TableB
        UNION ALL
        SELECT SKU, BeginYear+1, EndYear, OptionA, OptionB
        FROM CTE 
        WHERE BeginYear < EndYear
    )  
    INSERT INTO #TableA(SKU, OptionA, OptionB, Years)
    SELECT DISTINCT SKU, OptionA, OptionB, BeginYear
    FROM CTE 
    OPTION(MAXRECURSION 0)
    
    SELECT *
    FROM #TableA
    ORDER BY SKU, OptionA, OptionB, Years
    

    Here there’s no cartesian product.

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

Sidebar

Related Questions

I need to rewrite this query and I'm not allowed to use a subquery.
I need rewrite this url http://adresa.com/article.php?act=view&id=1113 to http://adresa.com/view/1113 I make it with mod_rewrite in
Here is a simplified version of the code I use. I need to rewrite
I know they do not hold across pattern matches (i.e. you need to rewrite
i'm trying to use iirf for what looks like asimple rewrite but it's not
I need to rewrite an image path on the following URLs: domain.com/system/index domain.com/system/view/12345 domain.com/system/search/term1:/term2:data/term3:/term4:data/term5
I need to rewrite some Python code into PHP (don't hate me, a customer
I need to rewrite some Perl code in python. So I'm looking for the
I need a rewrite in how the modifier 'truncate' is called, because it is
i have a mixed aspx/MVC webapp project and need to rewrite incoming URL's either

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.