Avatar of nutnut
nutnutFlag for United Kingdom of Great Britain and Northern Ireland asked on

Rows split to columns

Hi

I have a table that has 2 cols From and To

The values are say from=1 and to=9 and in the second row from=10 and to=20

I need SQL to turn that into 1 column listing 1,2,3,4,5,6,7,8,910,11,12,13,14,15,16,17,18,19,20

Thanks
Microsoft SQL Server 2005Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
nutnut

8/22/2022 - Mon
PortletPaul

can you provide a sample of the data and specify the table/fields?
are [from] and [to] fields integers?
are there other fields in the table to "group by"?
and, would there ever be gaps in the output number sequence (if so when)?

e.g.
category-A| 1,2,3,4,5,6
category-B| 20,21,23,24,25,26
category-C| 1,2,3,4,5,6,20,21,23,24,25,26 -- with gap ??
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
nutnut

Thanks

declare @t table ( [from] int, [to] int)
insert into @t values ( 1, 9 )
insert into @t values ( 10, 20 )

;with data as (
  select [from], [to] from @t
   union all
   select [from] + 1, [to] from data
   where [from] < [to]
   )
, ordered as ( select top 99.999999 percent [from] from data order by [from]  )

SELECT * FROM ordered

Was enough, I just want the data going down in one column.  Thanks for help
Your help has saved me hundreds of hours of internet surfing.
fblack61