Generating a sequence in sql server

前端 未结 2 1542
我在风中等你
我在风中等你 2021-01-14 00:18

I am working on a function that will take a low number and a high number as paramaters and returns a table containing everything between (and including).

I know I co

2条回答
  •  太阳男子
    2021-01-14 00:44

    Yes, you can use a recursive CTE to do this. For example to generate numbers between 10 and 20 inclusive:

    WITH f AS
    (
        SELECT 10 AS x
        UNION ALL
        SELECT x + 1 FROM f WHERE x < 20
    )
    SELECT * FROM f
    

提交回复
热议问题