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 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'm trying to use URL rewrite in my new project. But I also need
i'm totally bugged from this problem... i need to know how to rewrite this
Well for whatever reason MySQL does not support subqueries in a View. I'm stuck
I need to rewrite any url on my domain that starts with **/club/***anyPage* to
I'm not sure if this is even possible, but here goes: I have a
RewriteRule ^(dir1|file1) - [L] If this rule IS THE CASE then other rewrite rules
I have a situation where I need to rewrite from the root to default.aspx.
I am not an ASP developer so pretty lost here. Need to set up
I need a very quick fix in a mod_rewrite expression for drupal we have
Need a function that takes a character as a parameter and returns true if

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.