Forum Discussion

FabricUser25's avatar
FabricUser25
Frequent Visitor
2 years ago
Solved

Weird count behaviour for table in Warehouse

I have created a procedure to iterate over all the records within a config table and do things according to some logic that is not really imporant in this particular case. I assumed that count(*) sho...
  • FabricUser25's avatar
    2 years ago

    One more thing to note, as it turns out saving the result of count(*) query into a variable and comparing it to the iterator turns out to work properly.

     

    drop table if exists dbo.temp
    
    declare @iter int = 0
    
    select
    	1 x
    into
    	dbo.temp
    
    declare @limit int = (select count(*) from dbo.temp)
    
    while @limit>@iter
    begin
    	print @iter
    
    	set @iter += 1
    
    	if @iter=20
    		break
    end
    
    print 'finished'
    
    drop table if exists dbo.temp