I have a problem inserting more than 255 chars per column into an Excel file using INSERT INTO OPENROWSET from SQL Server

*爱你&永不变心* 提交于 2019-12-25 02:22:34

问题


I am getting an error while exporting data from SQL Server to an already created .xlsx file using openrowset.

It works fine most of times, but when the data comes in of the field as a large string, while inserting into Excel, it shows this error:

The statement has been terminated, string or binary data would be truncated.

Data gets inserted into table, but while inserting in Excel, this error appears. Please help me find a solution.


回答1:


As the error mentions "data would be truncated", you should be provide a longer string value into a placeholder or field that has a smaller storage size.

For example, the source field may have data type nvarchar(max) and in your SQL development or where a mapping exists, you assing the values into a smaller data size type. For example, in source table you have a string value 5000 characters, but during the process it is assigned to a nvarchar(4000) then a data truncation will occur

I would suggest you to check data mappings in your statements



来源:https://stackoverflow.com/questions/52477920/i-have-a-problem-inserting-more-than-255-chars-per-column-into-an-excel-file-usi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!