This way to split a recorset is simpler by using the NTILE() function.
Enjoi it.
This way to split a recorset is simpler by using the NTILE() function.
Enjoi it.
USE AdventureWorksDW; GO DECLARE @t INT, @bt INT,@dv INT SET @dv=8000 SELECT @bt=COUNT(*) FROM dbo.FactFinance IF (@bt%@dv)<>0 BEGIN SET @t=@bt/@dv + 1 END ELSE BEGIN SET @t=@bt/@dv END SELECT * ,NTILE(@t) OVER(ORDER BY TimeKey ASC) AS 'splitter' INTO #TEMP FROM dbo.FactFinance WHILE @t>0 BEGIN SELECT [TimeKey] ,[OrganizationKey] ,[DepartmentGroupKey] ,[ScenarioKey] ,[AccountKey] ,[Amount] FROM #TEMP WHERE splitter=@t SET @t=@t-1 CONTINUE END DROP TABLE #TEMP