Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one change the default varchar 255 of a column when importing data from Excel to Sql Server using Import Export Wizard?

I am trying to import data from excel to Sql Server using Import wizard. Everything seems fine in the first steps. The wizard is able to read the excel file and properly identify columns. But in the final step when the process actually runs, it fails giving the following errors:

Error 0xc020901c: Data Flow Task 1: There was an error with output column "AlternateName" (24) on output "Excel Source Output" (9). The column status returned was: "Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)

Error 0xc020902a: Data Flow Task 1: The "output column "AlternateName" (24)" failed because truncation occurred, and the truncation row disposition on "output column "AlternateName" (24)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component. (SQL Server Import and Export Wizard)

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Source - Sheet1$" (1) returned error code 0xC020902A. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure. (SQL Server Import and Export Wizard)

The column, AlternateName has max data length of 658 chars. The destination table has the column AlternateName defined as varchar(1000). So I was not sure why am I getting this error. But then I noticed this

enter image description here

I have a hunch that this may be causing the issue. But then how do I change the Source column defined as varchar 255 ?

like image 884
shashi Avatar asked Sep 15 '11 15:09

shashi


People also ask

Is varchar max 255?

VARCHAR(255) stores 255 characters, which may be more than 255 bytes.


1 Answers

You may need to write your own query in the wizard and cast the columns as varchar(1000) - I'm not 100% sure that will work. ALternately, how big is the sheet? The wizard only "looks down" so many rows (IIRC 10000 by default, it's a registry setting) to determine data type and width. Re-sort the excel file so that the longest AlternateName value is at the top.

like image 83
Wil Avatar answered Oct 12 '22 22:10

Wil