Попытка использовать оператор CONTINUE в простом l oop.
l oop работает без оператора IF = 16 и CONTINUE, но не работает с ними
DECLARE @counter INT
DECLARE @maxLocations INT
DECLARE @numLocations INT
SET @maxLocations = (SELECT MAX(calculated_host_listings_count) FROM [PracticeDB].[dbo].[AB_NYC_2019$])
SET @counter = 0
WHILE @counter<=@maxLocations
BEGIN
SET @numLocations =
(SELECT COUNT(*) FROM [PracticeDB].[dbo].[AB_NYC_2019$] WHERE calculated_host_listings_count = @counter)
IF(@numLocations=16)
BEGIN
CONTINUE
END
ELSE
BEGIN
PRINT CAST(@numLocations AS VARCHAR(6)) + ' rentals with ' +
CAST(@counter as VARCHAR(6)) + ' host listings'
END
SET @counter += 1
END
Результат без IF (@ numlocations = 16) ПРОДОЛЖЕНИЕ
0 rentals with 0 host listings
32303 rentals with 1 host listings
6658 rentals with 2 host listings
2853 rentals with 3 host listings
1440 rentals with 4 host listings
845 rentals with 5 host listings
570 rentals with 6 host listings
399 rentals with 7 host listings
416 rentals with 8 host listings
234 rentals with 9 host listings
210 rentals with 10 host listings
110 rentals with 11 host listings
180 rentals with 12 host listings
130 rentals with 13 host listings
70 rentals with 14 host listings
75 rentals with 15 host listings
16 rentals with 16 host listings
68 rentals with 17 host listings
Результат с IF & Continue (оригинальный код выше) переходит в бесконечное l oop, но когда я останавливаюсь Я получаю результаты вплоть до результата IF (16)
0 rentals with 0 host listings
32303 rentals with 1 host listings
6658 rentals with 2 host listings
2853 rentals with 3 host listings
1440 rentals with 4 host listings
845 rentals with 5 host listings
570 rentals with 6 host listings
399 rentals with 7 host listings
416 rentals with 8 host listings
234 rentals with 9 host listings
210 rentals with 10 host listings
110 rentals with 11 host listings
180 rentals with 12 host listings
130 rentals with 13 host listings
70 rentals with 14 host listings
75 rentals with 15 host listings