Export data from SQL Server to Excel Using OPENROWSET
I'm trying to import data from SQL server to Excel spreadsheet using OpenRowSet function. My code works but it skips thousands of rows in the spreadsheet and insert the data from the 3665th row. Does anyone know how to fix this? Below is the code I executed: USE webemt; GO INSERT INTO OPENROWSET ('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;Database=c:\AccreditedProgramsRpt_02042015.xlsx;', 'SELECT * FROM [AccreditedPrograms$]') SELECT Programs.Name, Programs.ProgramCode, Programs.StateCode, Programs.IsAccredited, Programs.HasLetterOfReview, Programs.UpdatedOn, Programs.Status , Programs.AccreditedOn, Programs.AccreditationExpiresOn, Programs.LetterOfReviewIssuedOn, Programs.LetterOfReviewExpiresOn FROM Programs WHERE Programs.Status in (1,2) order by Programs.Name asc GO Also enclosed is a screenshot of the excel spreadsheet : /storage/temp/2073-openrwoset.jpg
Try deleting the worksheet and replacing it with a blank one. Excel sometimes thinks it has rows (and from its perspective is probably right) when cell data is deleted but the rows that held that data were not also deleted.