use mytest go set rowcount 0 DECLARE @counter int DECLARE @effe float set nocount on SET @counter = 1 WHILE @counter < 10000 BEGIN SELECT @effe = cast (RAND()* 10000000 as int) select * from t10m_1 where c1 = @effe option (maxdop 1) SET NOCOUNT ON SET @counter = @counter + 1 SET NOCOUNT OFF if cast (@effe/100000 as int)=99 begin SELECT COUNT(*) FROM t1000 a INNER LOOP JOIN t1000 b ON b.c1 = a.c1 option (maxdop 1) end END GO