I'm loading a Notepad txt file into a SQL Table. I'm trying to use the BULK INSERT command but I keep getting this error:
Msg 4863, Level 16, State 1, Line 8
Bulk load data conversion error (truncation) for row 1, column 3 (column3).
The txt file has each column separated by a | symbol. I just need each set of text between each | | to be in it's own column.
For example:
|100|AA|BCD|200|
I need each of those to be separated into a column in a table. My code may be too simple right now but any help would be appreciated.
CREATE TABLE BMData2 (
column1 varchar(30),
column2 varchar(30),
column3 character(3),
column4 varchar(10),
column5 varchar(10),
column6 varchar(10),
column7 varchar(10),
column8 varchar(10),
column9 varchar(10),
column10 varchar(10),
column11 varchar(10),
column12 varchar(10),
column13 varchar(10),
column14 varchar(10),
column15 varchar(10),
column16 varchar(10),
column17 varchar(10),
column18 varchar(10),
column19 varchar(10),
column20 varchar(10),
column21 varchar(10),
column22 varchar(10),
column23 varchar(10),
column24 varchar(10),
column25 varchar(10),
column26 varchar(10),
)
BULK INSERT BMData
FROM '\\DBV\march_june\All march june Data.txt'
WITH
(Fieldterminator = '|',
ROWTERMINATOR = '\n');
Line of data looks like this:
AB|1410|MTH|ART|20150401|3|1600|1600|1556|2048|2048|2101|0|0|168|185|-4|13|17|1630|2054|ARTPROJECT|34|7|144||0|0|0|0|0|0|0|0|0||0|0|0|0|||0|0|0|0|||0|0|0|0|||0|0|0|0|||0|0|0|0|
I really only need 5 of these "data points" i.e. |data point| but my data comes like this and there are so many rows that the clean up is impossible in Excel or Notepad.
Remove the column headers in your text file.
BULK INSERT (Transact-SQL)
The FIRSTROW attribute is not intended to skip column headers.
Skipping headers is not supported by the BULK INSERT statement. When
skipping rows, the SQL Server Database Engine looks only at the field
terminators, and does not validate the data in the fields of skipped
rows.
Edit: Your sample data does not match the table you present. You table has 26 columns but the sample data has about double.
Create a test file with the following test data (no column headers):
Note that the last column has a NULL value. It is after the last | and before the NewLine character.
AB|1410|MTH|ART|20150401|3|1600|1600|1556|2048|2048|2101|0|0|168|185|-4|13|17|1630|2054|ARTPROJECT|34|7|144|
AB|1410|MTH|ART|20150401|3|1600|1600|1556|2048|2048|2101|0|0|168|185|-4|13|17|1630|2054|ARTPROJECT|34|7|144|
AB|1410|MTH|ART|20150401|3|1600|1600|1556|2048|2048|2101|0|0|168|185|-4|13|17|1630|2054|ARTPROJECT|34|7|144|
Use xml format file instead. It works much better. Here is sample based on #Ricardo C sample data.
1. Prepare xml file and save (c:\temp\bulk.xml in this example).
<?xml version="1.0" encoding="utf-8" ?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<!--list all fields in your .txt here-->
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="12" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="13" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="14" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="15" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="16" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="17" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="18" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="19" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="20" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="21" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="22" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="23" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="24" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="25" xsi:type="CharTerm" TERMINATOR='|' MAX_LENGTH="510" />
<FIELD ID="26" xsi:type="CharTerm" TERMINATOR='\r\n' MAX_LENGTH="510" />
<!-- the last is end of row -->
</RECORD>
<ROW>
<!-- List only what you need -->
<COLUMN SOURCE="1" NAME="Id" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="2" NAME="Id1" xsi:type="SQLINT"/>
<COLUMN SOURCE="3" NAME="Name" xsi:type="SQLVARYCHAR"/>
</ROW>
</BCPFORMAT>
Usage:
insert dbo.myTable
SELECT *
FROM OPENROWSET(BULK 'C:\temp\bulk.txt',
FORMATFILE='C:\temp\bulk.xml'
) AS t1;
I would use PowerShell to pre-process the original file and extract only the columns I need and put the extracted data to a new file.
Let's say the original source file is located at c:\temp\src.txt as follows(put your column name in the first line for easy process):
col1|col2|col3|col4|col5|col6|col7|col8|col9|col10
1|2|3|4|5|6|7|8|9|10
11|12|13|14|15|16|17|18|19|20
21|22|23|24|25|26|27|28|29|30
31|32|33|34|35|36|37|38|39|40
41|42|43|44|45|46|47|48|49|50
51|52|53|54|55|56|57|58|59|60
61|62|3|64|65|66|67|68|69|70
Now let's say I only need to get col2, col4, col5 and col9 data. So here is the PowerShell code
[string[]]$col_wanted = 'col2', 'col4', 'col5', 'col9'; #only need four columns out of 10 columns
$csv = import-csv -path c:\temp\src.txt -Delimiter '|';
$t=($col_wanted -join "|") + "`r`n";
foreach ($c in $csv)
{
$col_wanted | % -begin {[string]$s='';} -process {$s+=$c.$_+'|';} -end {$s = $s.Substring(0, $s.Length-1) + "`r`n"}
$t += $s
}
$t | Out-File -FilePath c:\temp\target.txt -Force;
If we open c:\temp\target.txt, we will see the result like this:
col2|col4|col5|col9
2|4|5|9
12|14|15|19
22|24|25|29
32|34|35|39
42|44|45|49
52|54|55|59
62|64|65|69
Now you can use bulk insert to do the data importing, but since we have the first row as column header, in the bulk insert, we need to set firstrow = 2, i.e. like the following
bulk insert MyTable
from 'c:\temp\target.txt'
with (FIELDTERMINATOR ='|', firstrow=2);
Related
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
The default collation name is "SQL_Latin1_General_CP1_CI_AS" when i create a table and import data using CSV file. I just want to set collation name as "Latin1_General_CI_AS" while importing data. Is there any possible way to configure this while importing data itself.
Use a Format File to Bulk Import Data.
For example 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="CharTerm" TERMINATOR="," MAX_LENGTH="7"/>
\<FIELD ID="2" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="25" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
\<FIELD ID="3" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="30" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
\<FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="11"/>
</RECORD>
<ROW>
\<COLUMN SOURCE="1" NAME="PersonID" xsi:type="SQLSMALLINT"/>
\<COLUMN SOURCE="2" NAME="FirstName" xsi:type="SQLVARYCHAR"/>
\<COLUMN SOURCE="3" NAME="LastName" xsi:type="SQLVARYCHAR"/>
\<COLUMN SOURCE="4" NAME="BirthDate" xsi:type="SQLDATE"/>
</ROW>
</BCPFORMAT>
And next, for example bulk insert :
BULK INSERT dbo.myTable
FROM 'D:\BCP\myFile.csv'
WITH (FORMATFILE = 'D:\BCP\myFileFormat.fmt');
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.
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.
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" />