I have a single table varchar, int, int like this:
OS MinSP MaxSP
-- ----- -----
2000 4 4
XP 2 3
Vista 0 2
7 0 1
What I want is a query which will generate a list of values like this:
- 2000 SP4
- XP SP2
- XP SP3
- Vista
- Vista SP1
- Vista SP2
- 7
- 7 SP1
Edit
Although MinSP and MaxSP a never more than one apart in my original example, it’s possible that they will both be the same or separated by more than one. I’ve changed the example to illustrate.
You would need a Tally table to do the following, but it beats a cursor and will grow dynamically with the next OS that is released. Your tally table will have to be zero based too.
EDIT: Fixed a typo and added a second version
Version 1 (You have not got a Tally Table):
This generates a numbers table on the fly using sys.all_columns. There are many ways of doing this, but you get the idea.
Version two (You have a Tally Table that is zero based):