BULK INSERT tab-delimited file - With commas in Description - sql

I am trying to import a CSV file With the BULK INSERT Function. I am doing it through SQL because it can be an automated process. The problem I picked up is that the CSV file I get from the client has commas in the Item Description i.e Rosetta 10,5x25x4 - When I try to import it that comma in the description causes a problem: Here is the Script I am running:
BULK INSERT ORDERS_DATA
FROM 'C:\back_orders_2013.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
TABLOCK
)
Is there a way to ignore that like in excel where you treat consecutive delimiters as one?

Here is the solution:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="12" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="13" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="14" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="15" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="16" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="17" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="18" xsi:type="CharTerm" TERMINATOR=',' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="19" xsi:type="CharTerm" TERMINATOR='\n' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="RKID" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="2" NAME="ORNO" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="3" NAME="PONO" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="4" NAME="ITEM_CODE" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="5" NAME="ITEM_DESCRIPTION" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="6" NAME="ORDER_QTY" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="7" NAME="DELIVER_QTY" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="8" NAME="B_QTY" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="9" NAME="RTS_DATE" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="10" NAME="PRICE" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="11" NAME="PLEV" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="12" NAME="DISCOUNT1" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="13" NAME="DISCOUNT2" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="14" NAME="DISCOUNT3" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="15" NAME="TOTAL" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="16" NAME="CURRENCY" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="17" NAME="ORDER_DATE" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="18" NAME="BKYN" xsi:type="SQLVARYCHAR" />
<COLUMN SOURCE="19" NAME="PENTA_REF" xsi:type="SQLVARYCHAR" />
</ROW>
</BCPFORMAT>
This works 100% and the error I received:
String or binary data would be truncated. The statement has been
terminated
Was because of the length of one of my data fields.

Related

BCP insert skip one DB column

I am using a BCP with a file format XML to import from a csv into a SQL database.
It works until I add a new column called DATERIF, that I should skip, but I cannot.
With the following templates, instead of skipping the column, the import is also filling that one, leaving the last one (MODELLO) empty,
I tried to add after the 6th column a row like this one, but in that case an error is raised at runtime.
<COLUMN SOURCE="0" NAME="DATERIF" xsi:type="SQLDATETIME" />
here the complete template file
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="20"
COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="HOSTNAME" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="2" NAME="IP_MACCH" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="3" NAME="LOGIN" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="4" NAME="T_TYPE" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="5" NAME="DATA_RIL" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="6" NAME="ORA_RIL" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="0" NAME="DATERIF" xsi:type="SQLDATETIME"/>
<COLUMN SOURCE="7" NAME="CUSTOMER" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="8" NAME="NUMORDINE" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="9" NAME="OPERATORE" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="10" NAME="SERIALNUM" xsi:type="SQLVARYCHAR" LENGTH="20"/>
<COLUMN SOURCE="11" NAME="MODELLO" xsi:type="SQLVARYCHAR" LENGTH="20"/>
</ROW>
</BCPFORMAT>
How can I skip this field an import in the following ones?
Thank you
Andrea
I am assuming that you are using MS SQL Server.
The scenario where a DB table has one or few additional column(s) is resolved by using a view. That view definition needs to exclude not needed columns. After that you can BULK INSERT into a view instead of the DB table.
It is documented in BOL: Using BULK INSERT with a view

SQL BCP Unknown Error while attempting to read format file on Ubuntu

I'm trying to automate some importing jobs to my SQL Server database and have the following XML format file:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharFixed" LENGTH="11" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="2" xsi:type="CharFixed" LENGTH="30" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="3" xsi:type="CharFixed" LENGTH="2" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="4" xsi:type="CharFixed" LENGTH="2" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="5" xsi:type="CharFixed" LENGTH="2" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="6" xsi:type="CharFixed" LENGTH="1" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="7" xsi:type="CharFixed" LENGTH="1" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="8" xsi:type="CharFixed" LENGTH="2" COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR="\n"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="cuit" xsi:type="SQLNUMERIC" PRECISION="11" />
<COLUMN SOURCE="2" NAME="denominacion" xsi:type="SQLVARYCHAR" LENGTH="30" />
<COLUMN SOURCE="3" NAME="imp_ganancias" xsi:type="SQLVARYCHAR" LENGTH="2" />
<COLUMN SOURCE="4" NAME="imp_iva" xsi:type="SQLVARYCHAR" LENGTH="2" />
<COLUMN SOURCE="5" NAME="monotributo" xsi:type="SQLVARYCHAR" LENGTH="2" />
<COLUMN SOURCE="6" NAME="integra_sociedad" xsi:type="SQLVARYCHAR" LENGTH="1" />
<COLUMN SOURCE="7" NAME="empleador" xsi:type="SQLVARYCHAR" LENGTH="1" />
<COLUMN SOURCE="8" NAME="actividad_monotributo" xsi:type="SQLVARYCHAR" LENGTH="2" />
</ROW>
</BCPFORMAT>
And it works fine on my local machine running windows 10 if I run the bcp command
bcp myDB.dbo.myTable IN File.txt -f File.xml -U x -P x -S myIp
But the problem is that I need to leave this commands running on a remote machine running on Ubuntu and when I do I get the following error
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Format File : Unknown error occurred while attempting to read.
And I have no Idea why this is happening, I tried changing permissions on the file and running as root but nothing changes.

SQL Bulk Upload/Copy with Format File Error

So, I have a table with the following structure;
CREATE TABLE [dbo].[LoadAgencyInfo](
       [Agency] [varchar](4) NULL,
       [Fund] [varchar](1) NULL,
       [Account] [varchar](14) NULL,
       [LName] [varchar](20) NULL,
       [FName] [varchar](9) NULL,
       [SSN] [varchar](9) NULL,
       [Prior] [varchar](3) NULL,
       [BalDue] [varchar](8) NULL,
       [DRSBal] [varchar](8) NULL,
       [Fill1] [varchar](16) NULL,
       [FileDate] [varchar](6) NULL,
       [Fill2] [varchar](3) NULL,
       [P1] [varchar](2) NULL,
       [P2] [varchar](2) NULL
) ON [PRIMARY]
GO
I then have a flat file that I intend to bulk upload to the database. The file format is as follows and is just a normal text file, see below; there are several different files but they all follow this format.
Sample Data
2000S10000252      VYUSBN              RUDXOD   0099882260000006824100000000                181802      
2300S20000350      TEVXXXX             TGXC     0025045640000000652800000000                052153      
 
The file is supposed to follow the format below based on character length. Each cell should fill with the correct information based on where the characters are in the file/record. The records with a width of zero fill should fill with zeros. The records with skip this field should skip over the particular field and not put any data into the cell.
File Break Down
Field Name
Character Start
Character End
Width
Agency
1
4
4
Fund
5
5
1
Account
6
19
14
LName
20
39
20
FName
40
48
9
SSN
49
57
9
Prior
58
60
3 (Zero fill, doesn’t come from text file default to 000)
BalDue
61
68
8
DrsBal
69
76
8 (Zero fill, doesn’t come from text file default to 00000000)
Fill1
77
92
16 (Skip this field)
FileDate
93
98
6
Fill2
99
105
7 (skip this field)
 
The flat file is supposed to follow a strict guideline in terms of character length, for example the first four characters belong to the agency cell, and the next character belongs to the fund cell, etc. Notice there aren’t any delimited characters so I am using a SQL format file to help process the records and input them into the database. However no matter what I do the appropriate cells are either not filled in or partially filled in and when I attempt to skip over fields the fields I am skipping get populated. I have tried changing the datatype to nvarchar but still doesn’t work. Sometimes the data gets garbbled and doesn’t translate properly.
See the format file below;
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
       <FIELD ID="1" xsi:type="CharFixed" MAX_LENGTH="4" />
       <FIELD ID="2" xsi:type="CharFixed" MAX_LENGTH="1"/>
       <FIELD ID="3" xsi:type="CharFixed" MAX_LENGTH="14"/>
       <FIELD ID="4" xsi:type="CharFixed" MAX_LENGTH="20"/>
       <FIELD ID="5" xsi:type="CharFixed" MAX_LENGTH="9"/>
       <FIELD ID="6" xsi:type="CharFixed" MAX_LENGTH="9"/>
       <FIELD ID="7" xsi:type="CharFixed" MAX_LENGTH="3"/>
       <FIELD ID="8" xsi:type="CharFixed" MAX_LENGTH="8"/>
       <FIELD ID="9" xsi:type="CharFixed" MAX_LENGTH="8"/>
</RECORD>
<ROW>
       <COLUMN SOURCE="1" NAME="Agency" xsi:type="SQLINT" LENGTH="4"/>
       <COLUMN SOURCE="2" NAME="Fund" xsi:type="SQLNVARCHAR" LENGTH="1"/>
       <COLUMN SOURCE="3" NAME="Account" xsi:type="SQLNVARCHAR" LENGTH="14"/>
       <COLUMN SOURCE="4" NAME="LName" xsi:type="SQLNVARCHAR" LENGTH="20"/>
       <COLUMN SOURCE="5" NAME="FName" xsi:type="SQLNVARCHAR" LENGTH="9"/>
       <COLUMN SOURCE="6" NAME="SSN" xsi:type="SQLINT" LENGTH="9"/>
       <COLUMN SOURCE="7" NAME="Prior" xsi:type="SQLINT" LENGTH="3"/>
       <COLUMN SOURCE="8" NAME="BalDue" xsi:type="SQLINT" LENGTH="8"/>
       <COLUMN SOURCE="9" NAME="DRSBal" xsi:type="SQLINT" LENGTH="8"/>
</ROW>
</BCPFORMAT>
 
Any help as to why this isn’t working would be very beneficial
So, I’ve made some adjustments to the SQL format xml file and to the SQL command itself as you can see below. The issue now is that all of the appropriate fields are populated when I run the command, but the last cell in the first row gets all the subsequent row’s data as there are over 2000+ rows. What should happen is after the sixth character in the FileDate field the data should move to the next row instead of putting all of the subsequent rows in the FileDate field. I have tried updating the ROWTERMINATOR field with 0x0a, 'n, 'r, 'r'n, 'n'r but nothing seems to work. I am also puzzled as to why the command isn’t respecting the MAX_LENGTH attribute as I have it set to 6 and why none of the row terminators aren’t working? I’ve been at this for days and it is driving me wild.
The source file is plan text from a unix machine and only has lf as the row terminator. I cant post the image of the data because I dont have 10 rep points.
XML File
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharFixed" LENGTH="4" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="2" xsi:type="CharFixed" LENGTH="1" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="3" xsi:type="CharFixed" LENGTH="14" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="4" xsi:type="CharFixed" LENGTH="20" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="5" xsi:type="CharFixed" LENGTH="9" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="6" xsi:type="CharFixed" LENGTH="9" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="7" xsi:type="CharFixed" LENGTH="3" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="8" xsi:type="CharFixed" LENGTH="8" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="9" xsi:type="CharFixed" LENGTH="8" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="10" xsi:type="CharFixed" LENGTH="16" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="11" xsi:type="CharTerm" MAX_LENGTH='6' TERMINATOR="0x0a" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="Agency" xsi:type="SQLCHAR" />
<COLUMN SOURCE="2" NAME="Fund" xsi:type="SQLCHAR" />
<COLUMN SOURCE="3" NAME="Account" xsi:type="SQLCHAR" />
<COLUMN SOURCE="4" NAME="LName" xsi:type="SQLCHAR" />
<COLUMN SOURCE="5" NAME="FName" xsi:type="SQLCHAR" />
<COLUMN SOURCE="6" NAME="SSN" xsi:type="SQLCHAR" />
<COLUMN SOURCE="7" NAME="Prior" xsi:type="SQLCHAR" />
<COLUMN SOURCE="8" NAME="BalDue" xsi:type="SQLCHAR" />
<COLUMN SOURCE="9" NAME="DRSBal" xsi:type="SQLCHAR" />
<COLUMN SOURCE="10" NAME="Fill1" xsi:type="SQLCHAR" />
<COLUMN SOURCE="11" NAME="FileDate" xsi:type="SQLNCHAR" />
</ROW>
</BCPFORMAT>

SQL Bulk copy (unicode)

i have a problem with bulk load into my database. Server throws error "String or binary data would be truncated", but my data seems to be ok.
Im using UTF-16LE data file with XML format file.
Thanks for your answers
Here's my format file:
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="NCharTerm" TERMINATOR=";\0" />
<FIELD ID="2" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="3" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="4" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="5" xsi:type="NCharTerm" TERMINATOR=";\0" />
<FIELD ID="6" xsi:type="NCharTerm" TERMINATOR=";\0" />
<FIELD ID="7" xsi:type="NCharTerm" TERMINATOR=";\0" />
<FIELD ID="8" xsi:type="NCharTerm" TERMINATOR=";\0" />
<FIELD ID="9" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="10" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="11" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="12" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="13" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="14" xsi:type="NCharTerm" TERMINATOR=";\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="15" xsi:type="NCharTerm" TERMINATOR="\n\0" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="RefundId" xsi:type="SQLINT"/>
<COLUMN SOURCE="2" NAME="Date" xsi:type="SQLNCHAR"/>
<COLUMN SOURCE="3" NAME="VariableSymbol" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="4" NAME="RefundType" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="5" NAME="TollAmount" xsi:type="SQLNUMERIC" PRECISION="28" SCALE="12"/>
<COLUMN SOURCE="6" NAME="DepositAmount" xsi:type="SQLNUMERIC" PRECISION="28" SCALE="12"/>
<COLUMN SOURCE="7" NAME="OperativeAmount" xsi:type="SQLNUMERIC" PRECISION="28" SCALE="12"/>
<COLUMN SOURCE="8" NAME="OIAmount" xsi:type="SQLNUMERIC" PRECISION="28" SCALE="12"/>
<COLUMN SOURCE="9" NAME="Currency" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="10" NAME="Prefix" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="11" NAME="BankAccountNumber" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="12" NAME="BankCode" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="13" NAME="BankIBANCode" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="14" NAME="BankSwiftCode" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="15" NAME="BeneficiaryName" xsi:type="SQLNVARCHAR"/>
</ROW>
</BCPFORMAT>
Here's my data file:
301;2008/05/05;444441;CN;50;1550;70;900;CZK;;8888888888;0800;;;
302;2008/05/06;444442;UP;50;1550;70;900;CZK;;8888888888;1234;;;
303;2008/05/07;444443;OP;50;1550;70;900;CZK;;8888888888;;;;
304;2008/05/08;444444;CN;60;1550;70;900;CZK;;;0400;;;
305;2008/05/09;444445;UP;70;1550;70;900;CZK;;1234567891;0800;;;
306;2008/05/10;444446;OP;80;1550;70;900;CZK;;8888888888;0800;;;
307;2008/05/11;444447;CN;90;1550;70;900;CZK;;8888888888;0800;CZ7308000000008888888888;;
308;2008/05/12;444448;UP;100;1550;70;900;CZK;;8888888888;0800;;12345678901;
309;2008/05/13;444449;OP;110;1550;70;900;CZK;;;;12234567890qqqq;COBADEFF;**123456789012345678901234567890qqqq**
310;2008/05/14;444450;CN;120;1550;70;900;CZK;;;;;COBADEFF;Herr Norbert Ramscheid
312;2008/05/16;444452;OP;140;1550;70;900;CZK;;;;RO49AAAA1B31007593840000;RNCBROBU;Mr. Papalescu
313;2008/05/17;444453;CN;150;1550;70;900;CZK;;678907890;;;RNCBROBU;Mojmir Fagaras
314;2008/05/18;444454;UP;160;1550;70;900;CZK;;;;;RNCBROBU;Mr. Without Bank Account
315;2008/05/19;444455;OP;170;1550;70;900;CZK;;;;RO49AAAA1B31007593840000;;NoSWIFT Bill
316;2008/05/20;444456;CN;180;2000;70;900;CZK;;;;RO49AAAA1B31007593840000;RNCBROBU;
317;2008/05/21;444457;UP;190;1550;70;900;CZK;;;;DE89370400440532013000;COBADEFF;
I assume there could be a problem with a destination table where the data should be loaded into.
Example
E.g. when you are loading data in string of 10 characters into the column which is e.g. varchar(6) data type, the data could not be loaded into this column as it supports only 6 characters and you would get the error as you are getting now - the data would be truncated.

sql bulk insert non-standard characters

I am importing data into a sql table from a csv using an xml format file.
When I perform the import it all works well but some extended characters are showing up incorrectly with things like this '▓' the one in particular is the '²'.
I am assuming it is something to do with the encoding of the file and me not telling the import how to handle it but I'm not 100% sure.
My CSV looks like the following
"2","4567","2","234562","","MAX","","2452","m²",""," ","254352"
and my import file
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR='"' />
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="12" xsi:type="CharTerm" TERMINATOR='","' />
<FIELD ID="13" xsi:type="CharTerm" TERMINATOR='"\r\n' />
</RECORD>
<ROW>
<COLUMN SOURCE="2" NAME="PARCELID" xsi:type="SQLINT"/>
<COLUMN SOURCE="3" NAME="PROPID" xsi:type="SQLINT"/>
<COLUMN SOURCE="4" NAME="LOT" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="5" NAME="RPLAN" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="6" NAME="SECTION" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="7" NAME="PARISH" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="8" NAME="COUNTY" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="9" NAME="AREA" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="10" NAME="AREATYPE" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="11" NAME="ZONING" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="12" NAME="MAPID" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="13" NAME="LOTPLAN" xsi:type="SQLNVARCHAR"/>
</ROW>
</BCPFORMAT>
I'm importing it using the sql command
BULK INSERT [parcel]
FROM 'c:\test\PARCEL.csv'
WITH (FORMATFILE = 'c:\test\PARCEL.xml', KEEPIDENTITY, FIRSTROW = 2, KEEPNULLS)
and my table structure looks like
[PARCELID] [int] NOT NULL
[PROPID] [int] NULL
[LOT] [nvarchar](255) NULL
[RPLAN] [nvarchar](255) NULL
[SECTION] [nvarchar](255) NULL
[PARISH] [nvarchar](255) NULL
[COUNTY] [nvarchar](255) NULL
[AREA] [nvarchar](50) NULL
[AREATYPE] [nvarchar](255) NULL
[ZONING] [nvarchar](255) NULL
[MAPID] [nvarchar](255) NULL
[LOTPLAN] [nvarchar](255) NULL
I have tried setting the bulk insert datafiletype to both 'widenative' and 'widechar' but to no avail.
Is there something else I'm missing here?
Turns out I needed to set the collation on the column itself like
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR='","' COLLATION="Latin1_General_CI_AS" />