Answered by:
error while exporting data from sql server to excel

Question
-
Hi,
I am trying to export data from sql server to excel.The query that I used is s follows
INSERT INTO OPENROWSET( 'Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\Folder1\abc.xls','select * from [Sheet1$A1:IV65000]')
select
column1,column2.... from Table1I get the following error message while doing so..
String or binary data would be truncated.
The statement has been terminated.One of the column's holds data more than 225 characters.
What is the way to correct this, i want the whole data of the colum in the excel sheet.Saturday, July 26, 2014 4:00 PM
Answers
-
It's probably better to either have Excel to connect to run the query, or have a separate program to talk both to SQL Server and Excel. What is happening now is that SQL Server asks the Jet engine about the data types. But Excel has, in difference to SQL Server, a dynamic idea of what is the data type. So it reports the current values. So it could be that because the current longest value in a column is 50 chars, Excel reports 50 chars, and that's when things starts to go wrong.
Look at the Import/Export wizard.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se- Proposed as answer by Elvis Long Thursday, July 31, 2014 11:18 AM
- Marked as answer by Elvis Long Thursday, August 7, 2014 4:31 AM
Saturday, July 26, 2014 9:42 PM -
Hi Umesh,
May be below links could be helpful to you:
http://support.microsoft.com/kb/189897
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926&whichpage=2
Regards
Avijit
- Edited by Avijit_Gupta Sunday, July 27, 2014 2:32 PM
- Proposed as answer by Elvis Long Thursday, July 31, 2014 11:18 AM
- Marked as answer by Elvis Long Thursday, August 7, 2014 4:31 AM
Sunday, July 27, 2014 2:22 PM -
I haven't had great luck with the INSERT INTO OPENROWSET method. Can you try one of the many samples from one of these 3 links?
http://www.mssqltips.com/sqlservertip/1540/insert-update-or-delete-data-in-sql-server-from-excel/
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.
- Marked as answer by Elvis Long Thursday, August 7, 2014 4:31 AM
Saturday, August 2, 2014 11:19 PM
All replies
-
You can split your string in SQL using left, mid, rigth and left you can use concatenate in your spreadsheet. It's the easier way.
Hope this post helped you
Saturday, July 26, 2014 4:14 PM -
It's probably better to either have Excel to connect to run the query, or have a separate program to talk both to SQL Server and Excel. What is happening now is that SQL Server asks the Jet engine about the data types. But Excel has, in difference to SQL Server, a dynamic idea of what is the data type. So it reports the current values. So it could be that because the current longest value in a column is 50 chars, Excel reports 50 chars, and that's when things starts to go wrong.
Look at the Import/Export wizard.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se- Proposed as answer by Elvis Long Thursday, July 31, 2014 11:18 AM
- Marked as answer by Elvis Long Thursday, August 7, 2014 4:31 AM
Saturday, July 26, 2014 9:42 PM -
Erland, I guess in this case the problem is the maximun lenght (excel side). It's common to separate (sql side) and concatenate (excel side) the string.Sunday, July 27, 2014 9:35 AM
-
Hi Umesh,
May be below links could be helpful to you:
http://support.microsoft.com/kb/189897
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926&whichpage=2
Regards
Avijit
- Edited by Avijit_Gupta Sunday, July 27, 2014 2:32 PM
- Proposed as answer by Elvis Long Thursday, July 31, 2014 11:18 AM
- Marked as answer by Elvis Long Thursday, August 7, 2014 4:31 AM
Sunday, July 27, 2014 2:22 PM -
I haven't had great luck with the INSERT INTO OPENROWSET method. Can you try one of the many samples from one of these 3 links?
http://www.mssqltips.com/sqlservertip/1540/insert-update-or-delete-data-in-sql-server-from-excel/
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.
- Marked as answer by Elvis Long Thursday, August 7, 2014 4:31 AM
Saturday, August 2, 2014 11:19 PM