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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:36:28+00:00 2026-06-02T02:36:28+00:00

Having a table like this: FromKey | ToKey | Value ———————— 1 | 4

  • 0

Having a table like this:

FromKey | ToKey | Value
------------------------
 1      |  4    | AAA 
 5      |  6    | BBB

what is the most efficient way to get the following result?

Key  | Value
-----------------
 1   | AAA 
 2   | AAA 
 3   | AAA 
 4   | AAA 
 5   | BBB 
 6   | BBB

I know how to do it using a table function and CROSS APPLY, but that approach is slow for big tables. I wonder if there is a faster solution.

  • 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-02T02:36:29+00:00Added an answer on June 2, 2026 at 2:36 am

    Here is one way to try (full example, runnable as-is):

    -- Dummy data
    DECLARE @Data TABLE (FromKey INTEGER, ToKey INTEGER, Value VARCHAR(10))
    INSERT @Data VALUES (1,4,'AAA'),(5,6,'BBB')
    
    -- table of numbers, 1-100 for demo purposes
    DECLARE @Numbers TABLE (Num INTEGER PRIMARY KEY)
    INSERT @Numbers
    SELECT TOP 100 ROW_NUMBER() OVER (ORDER BY object_id)
    FROM sys.objects
    
    SELECT n.Num, d.Value
    FROM @Data d
        JOIN @Numbers n ON d.FromKey <= n.Num AND d.ToKey >= n.Num
    

    What I would do, is create a physical “Numbers” table in your database, and populate with numbers from 1 to n, where n is a large enough number to cover your needs. This would be a one off table/data creation – but then the table can be used for purposes like the above.

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

Sidebar

Related Questions

I'm having the following problem. Imagine my mySQL table looks like this: id range
I have user table having fields gender and first name like this.. The value
I am having a table structure like this: Table : emp_details id name value
I am having a table with records like this in MS Access: ID field2
I'm having a table looking something like this: CREATE TABLE `Calls` ( `calendar_id` int(11)
I have a table like this: `id|value 1|2 2|8 3|5 4|6 5|10 6|7` I
I'm having a table like this one: ------------------------------- | NrOfVisitors | Year | Month
i am having table structure like this table1 table2 pid pname pid uid cat
Think about a table like this ID Value 100 1 100 3 101 1
i have a table like this: +------------------------+ |Key| value | name | +---+-------+------------+ 1

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.