Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 1.85M records

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-14 : 10:17:12
Sql 2008R2, i have a table with 1.85 million rows that i need to export to excel and am running into insufficient memory errors. Not much of a surprise there. So it's apparent i will need to do this in chunks. I know i can 'select top 10000' to get those records, but how would i select 10001 to 20000, etc, and so on to get these batches downloaded?

thanks as always.

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-14 : 10:19:24
<bangs head on table>

WHY Excel??? What are you going to do with the data? NO ONE is going to look at that


</bangs head on table>

But if you need rope...doe the table an have identity column or a datetime column?

You might need to create a paging VIEW and then bcp out the data that way




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-14 : 10:25:34
quote:
Originally posted by WJHamel

Sql 2008R2, i have a table with 1.85 million rows that i need to export to excel and am running into insufficient memory errors. Not much of a surprise there. So it's apparent i will need to do this in chunks. I know i can 'select top 10000' to get those records, but how would i select 10001 to 20000, etc, and so on to get these batches downloaded?

thanks as always.


dump data onto temporary table with identity column and run a looping logic to select a data range from it like

WHILE @startvalue <=@maxID
BEGIN

...Excel export logic
WHERE RowID BETWEEN @startvalue and @startvalue + 10000

change @strtvalue each time to @startvalue + 10001 inside loop


store MAX(RowID) value to @maxid before loop



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-14 : 10:30:56
why excel? because when the customer asks for excel data they get excel data. "mine is not to question why, blah, blah (something about do or die, i think).

thanks again.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-14 : 11:01:17
Yes, but your job is also to ask questions

Like

"Who is going to look at 1.85 million rows in Excel?"

"What do you plane to do with the data?"

See, there are opportunities for you to lead them down the correct path

MOO



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-02-14 : 15:16:49
quote:
why excel? because when the customer asks for excel data they get excel data. "mine is not to question why, blah, blah (something about do or die, i think).
Perhaps you don't have to question, but you can point out that Excel can only hold about 1 million rows per sheet.

Don't take this the wrong way, but when customers make stupid requests and you fulfill them without question, they make more, even stupider requests. There's nothing wrong with educating a customer on understanding and improving their requests.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-02-14 : 15:36:49
Unless "Excel" really means PowerPivot?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-14 : 15:48:21
How far is the run to N'Orleans for you?

Fat Tuesday is around the corner



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-15 : 14:48:20
New Orleans? You mean the new murder capital of the US? about two and a half hrs away. They're calling it "Murder Gras" this year. You won't get me anywhere near there. There's a much better jazz festival coming up there in April!. I'll risk that if i can conceal my Desert Eagle successfully.
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-15 : 14:50:17
By the way, i do have powerpivot added on to Excel 2010. That doesn't increase it's row capacity, does it? At any rate, it's above my pay grade to challenge anyone's thinking around here. They're gonna get what they're gonna get.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-02-16 : 04:30:09
Standard Excel can only hold 1048576 rows of data.
The PowerPivot add-in for Excel can hold hundreds of millions of rows.
Also, the PowerPivot add-in has it's own Import from SQL method.




N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -