Is it possible to write sql query (in mssql), that returns decimals from given r开发者_JS百科ange (each in seperate row)? e.g.
11
12
13
14
...
Not sure what you want
declare @start int=11;
declare @end int=26;
with cte as(
select @start as col union all
select COL+1 from cte where col+1<=@end)
select * from cte
Using Itzik Ben-Gan's technique (this will get you numbers up to 4,294,967,296) for producing a numbers table:
WITH
L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
L1 AS(SELECT 1 AS c FROM L0 AS A CROSS JOIN L0 AS B),
L2 AS(SELECT 1 AS c FROM L1 AS A CROSS JOIN L1 AS B),
L3 AS(SELECT 1 AS c FROM L2 AS A CROSS JOIN L2 AS B),
L4 AS(SELECT 1 AS c FROM L3 AS A CROSS JOIN L3 AS B),
L5 AS(SELECT 1 AS c FROM L4 AS A CROSS JOIN L4 AS B),
Nums AS(SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS n FROM L5)
SELECT n FROM Nums WHERE n between 11 and 20
精彩评论