简体   繁体   中英

Error while importing table data through bcp command in SQL server

I am trying to import data into a table through bcp command line utility. Earlier the error i was facing was of right truncation, i changed the data types in both my tables as nvarchar and ran the FMT command using the -n switch, now the error seems to have changed but i still cant import the data.

The command i use to import is as follows:

bcp ABC.ABC.DIM_Sales_Channel in C:\temp\datafile\DIM_Sales_Channel.dat -f C:\temp\formatcorrected\DIM_Sales_Channel.fmt -T

The error shown is as follows:

[Microsoft][SQL Server Native Client 11.0][SQL Server]Conversion not allowed from the given field type 0x38 for field 8 to column 8.




11.0
9
1       SQLINT              0       4       ""   1     Sales_Channel_SK                               ""
2       SQLINT              0       4       ""   2     Sales_Channel_ID                               ""
3       SQLNCHAR            2       36      ""   3     Sales_Channel_Code                             Latin1_General_CI_AI
4       SQLNCHAR            2       36      ""   4     Sales_Channel_Level_1                          Latin1_General_CI_AI
5       SQLNCHAR            2       36      ""   5     Sales_Channel_Level_2                          Latin1_General_CI_AI
6       SQLDATETIME         1       8       ""   6     Inserted_Date                                  ""
7       SQLDATETIME         1       8       ""   7     Modified_Date                                  ""
8       SQLINT              1       4       ""   8     batchno                                        ""
9       SQLINT              1       4       ""   9     Status                                         ""

[Microsoft][SQL Server Native Client 11.0][SQL Server]Conversion not allowed from the given field type 0x38 for field 8 to column 8.

Any clues?

This error occurs when the columns in your FMT file mismatch with your destination table/Source tables, i had created an intermediate staging table for moving my data correctly and that was causing the issue here. It was resolved by taking the fmt file of my intermediate staging table.

This error occurred for me too. There is no mismatch in columns but I think its throwing error for mismatch in datatypes for the field 8 in your data file and column 8 in your destination table.

In my case I faced the same issue though the both datatypes of source and destination file are the same (datetime in my case). I tried format file and everything but nothing works.

The one thing that worked for me is to create an empty table in staging the same as my destination table using the below query.

SELECT * INTO schema.newtable FROM schema.oldtable WHERE 1 = 0;

Then insert the data into the empty table using insert query and then you can easy queryout and put that data into destination table using BCP with no issues.

Same here. The problem is the order of the columns on the DB does not match the order of the columns on the.fmt file (specially the data type).

For me, worked to drop and create the table in the same order as the.fmt file. Something I could do because was a brand new table, no data, no relationship.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM