• Papil - Wednesday, January 3, 2018 2:52 PM

    I want to split one of the column's data into 8 equal parts.
    For eg. i have 73 rows currently in one of column of table temp. I want to get 9-10 rows in every sql statement. I tried below query it splits the whole table data in two parts. But i want to split in 8 parts -(73/8). A sql cursor would be helpful in order to make it more dynamic. because the numbers of the rows could increase but i still want it to split in 8 parts only.

           DECLARE @CountOf int,@Top int,@Bottom int

    SELECT @CountOf=COUNT(*) FROM temp

    SET @Top=@CountOf/2

    SET @Bottom=@CountOf-@Top

    SELECT TOP (@Top) * FROM temp ORDER BY 1 asc

    SELECT TOP (@Bottom) * FROM temp ORDER BY 1 desc

    please help.

    Thanks.

    Please use ROW_Count()   OR  OFFSET FETCH for your purpose.