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.
Here is one way to try (full example, runnable as-is):
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.