SQL循环内再加循环问题
DECLARE @i INT, @h INT,@Nun INTSET @i = 0 SET @h = 0SET @Nun = 1WHILE @i < 5 /*循环一*/ BEGIN WHILE @h < 5/*循环二*/ BEGIN PRINT @Nun /*循环一加循环二这里输出应该是25次才对,但他只输出了5次。*/ SET @Nun=@Nun+1 SET @h = @h + 1 END SET @i = @i + 1 END
DECLARE @i INT, @h INT,@Nun INTSET @i = 0 --SET @h = 0SET @Nun = 1WHILE @i < 5 /*循环一*/ BEGIN SET @h = 0 WHILE @h < 5/*循环二*/ BEGIN PRINT @Nun /*循环一加循环二这里输出应该是25次才对,但他只输出了5次。*/ SET @Nun=@Nun+1 SET @h = @h + 1 END SET @i = @i + 1 END
[解决办法]
DECLARE @i INT, @h INT,@Nun INTSET @i = 0 SET @Nun = 1WHILE @i < 5 /*循环一*/ BEGIN SET @h = 0 WHILE @h < 5/*循环二*/ BEGIN PRINT @Nun /*循环一加循环二这里输出应该是25次才对,但他只输出了5次。*/ SET @Nun=@Nun+1 SET @h = @h + 1 END SET @i = @i + 1 END/*12345678910111213141516171819202122232425*/