SQLTeam.com | Weblogs | Forums

How to export data to excel when it have data exceed million rows?

I work on SQL server 2012 I have select statement return 1.5 million rows so i need to export
these data to Excel file or more files
so how to do that

DECLARE @Export varchar(max) 

SET @Export = 
'INSERT INTO OPENROWSET(''Microsoft.ACE.OLEDB.12.0'',''Excel 12.0 Xml;HDR=YES;Database='+ @ExportFilePath +''',''SELECT * FROM [Sheet1$]'')

SELECT 
PartNumberC , 
CompanyNameC , 
PartNumberX,
CompanyNameX , 
[Status]  
from #TempReplacementImporter' ;

EXECUTE (@Export);

Try SSIS Package ..

Or

PowerShell ..

1.5 million rows into EXCEL .. means too much
Split it up into small bits

Good Luck

1 Like

this is good can you please tell me how

if use ssis how to do that

Please Google Serach

Why?

1 Like

Is this a one-time operation or something you need to automate? If you need to automate the process then you should utilize SSIS or SSRS.

If the goal is to output to Excel - then you are limited on how many rows can be exported, and since you are still on SQL Server 2012 the output is XLS which is limited to 65,536 rows in each sheet.

If you have SSRS 2016 or higher, you can create a report that will output to an XLSX file - but that is also limited. XLSX files can have 1,048,576 rows per sheet...

If you can support a different file format - then I would recommend using SSIS to output a pipe-delimited file, or you can use Powershell to create the file. For the greatest control in Powershell you need to be on version 7 - which includes the ability to define the delimiters and how/when to use quotes.

1 Like

Why, on this good Green Earth, is anyone trying to export a million + rows to Excel to begin with? I'm not being sarcastic... I'm trying to be a bit practical. What's the end purpose of doing such a thing?

3 Likes

Jeff

I was thinking the same thing ..

Looks Un Usual