I try to insert data from a textfile into a SQL Server 2016 table with a computed column with bcp.
My bcp command:
bcp Test.dbo.myFirstImport IN D:\myFirstImport.txt -f D:\myFirstImport.xml –T
My table:
CREATE TABLE [dbo].[MyFirstImport](
       [PersonID] [smallint] NULL,
       [FirstName] [varchar](25) NULL,
       [LastName] [varchar](30) NULL,
       [BirthDate] [date] NOT NULL,
       [YearMonthCom]  AS (datepart(year,[BirthDate])*(100)+datepart(month,[BirthDate])) PERSISTED
) ON [PRIMARY]
My Data (tab separated):
1   Anthony   Grosse      1980-02-23
2   Alica     Fatnowna    1963-11-14
3   Stella    Rosenhain   1992-03-02
My 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="\t" MAX_LENGTH="7"/>
  <FIELD ID="2" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="25" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="30" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="11"/>
  <!--
  <FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="11"/>
  <FIELD ID="5" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="12"/>
  -->
 </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"/>
  <!--
  <COLUMN SOURCE="5" NAME="YearMonthCom" xsi:type="SQLINT"/>
  -->
 </ROW>
</BCPFORMAT>
My error
SQLState = 37000, NativeError = 1934 Error = [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Fehler bei INSERT, da die folgenden SET-Optionen falsche Einstellungen aufweisen: "QUOTED_IDENTIFIER". Überprüfen Sie, ob die SET-Optionen für die Verwendung mit indizierte Sicht en und/oder Indizes für berechnete Spalten und/oder gefilterte Indizes und/oder Abfragebenachrichtigungen und/oder XML-Datentypmethoden und/oder Vorgänge für rä umliche Indizes richtig sind. BCP copy in failed
And in English
INSERT failed because the following SET options have incorrect settings: "QUOTED_IDENTIFIER". Verify that the SET options are correct for use with indexed views and / or indexes on computed columns and / or filtered indexes and / or query notifications and / or XML data type methods and / or spatial indices operations
I created another table without that computed column and bcp worked, just to be sure it is an issue with the computed column. Then I recreated the table (with computed column) with QUOTED_IDENTIFIER set to ON - see Jacob's comment - and it still did not work. But when I started bcp with -q it worked. So thank you, Jacob!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With