0

I have used opencsv libray to write the ResultSet in a csv file,using the writeAll method.Since the database is very big i have to split database records and write them to different csv files(For example every 1000 rows must be written in different files.) I have read about this but i havent suceded.I have used something like

select * from table1
Order by id
OFFSET 0 FETCH NEXT 1000 ROWS ONLY;

but it doesnt work.Can someone tell me how to achieve this please?

Nana30
  • 7
  • 5

2 Answers2

0

try the following:

select * from table1
Order by id
OFFSET 0 ROWS 
FETCH NEXT 1000 ROWS ONLY;

Thanks.

sacse
  • 3,634
  • 2
  • 15
  • 24
  • Oh, you are using SQL server 2008, these features (Offset/Fetch) are from SQL server 2012 onwards. – sacse Dec 20 '17 at 15:27
  • Well is there another way i can achieve something like this? – Nana30 Dec 20 '17 at 15:29
  • There are very good methods provided in the following link: https://stackoverflow.com/questions/2244322/how-to-do-pagination-in-sql-server-2008 – sacse Dec 20 '17 at 15:30
0

If somebody else needs it :

WITH CTEResults AS
(
    SELECT IDColumn, SomeField, DateField, ROW_NUMBER() OVER (ORDER BY DateField) AS RowNum
    FROM MyTable
)

SELECT * 
FROM CTEResults
WHERE RowNum BETWEEN 10 AND 20;
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
Nana30
  • 7
  • 5