create while loop with cte

后端 未结 2 712
我在风中等你
我在风中等你 2021-02-04 16:40

how to create sql server cte from a while loop
my loop like this

  declare @ind as int
  declare @code as nvarchar
  set @ind  = 0
   while @ind < 884
           


        
2条回答
  •  一生所求
    2021-02-04 17:14

    Below query selects values from 0 to 884:

    ;WITH T(Num)AS
    (
        SELECT 0 
        UNION ALL
        SELECT Num+1 FROM T WHERE T.Num < 884
    )SELECT Num FROM T 
    OPTION (MAXRECURSION 0);
    

提交回复
热议问题