hi to all,
i have table like below
from end 200 204 300 302 10 10 170 172
here i want to pass from and end as loop wise
my expected output is
value 200 201 202 203 204 300 301 302 10 170 171 172
Technology Tips and News
hi to all,
i have table like below
from end 200 204 300 302 10 10 170 172
here i want to pass from and end as loop wise
my expected output is
value 200 201 202 203 204 300 301 302 10 170 171 172
create table test (id int identity(1,1), [from] int, [to] int) Insert into test values(200,204),(300,302),(10,10),(170,172) ;WITH Num1 (n) AS ( SELECT 1 as n UNION ALL SELECT n+1 as n FROM Num1 Where n<101), Num2 (n) AS (SELECT 1 FROM Num1 AS X, Num1 AS Y), Nums (n) AS (SELECT ROW_NUMBER() OVER(ORDER BY n)-1 FROM Num2) Select n from test Cross apply (select n from nums) d(n) Where n>=[From] and n<=[to] Order by id drop table test
Hi ,
In Master database we a table which can be used. But not sure upto what numbers it is available in this table as I am unable to connect to SQL Server database and check. Please consider the below as a pseudo code
select s.number from master.dbo.spt_values s join yourtable on s.number >= yourtable.start and s.number <= yourtable.end WHERE Type = 'P'
Give this a go:
DECLARE @table TABLE (fromInt INT, toInt INT) INSERT INTO @table (fromInt, toInt) VALUES (200, 204), (300, 302), (10 , 10 ), (170, 172) ;WITH rCTE AS ( SELECT fromInt AS value, toInt FROM @table UNION ALL SELECT value + 1, toInt FROM rCTE WHERE value + 1 <= toInt ) SELECT value FROM rCTE ORDER BY value
hi celko,
thanks for your comments . its helpful. i am using SQL Server 2008 R2 i cant access Series table.