The bcp command that I am using:
bcp TableName format nul -c -f c:\folder\TargetFile.xml -x -S ServerName -T -q
I think I just need the fields to have a type of xsi:type=”CharFixed” rather then xsi:type=”CharTerm”.
The xml that it creates which doesn’t work for me:
<?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="24" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="150" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="150" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="20" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="12" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="UID" xsi:type="SQLNCHAR"/>
<COLUMN SOURCE="2" NAME="FNAME" xsi:type="SQLNCHAR"/>
<COLUMN SOURCE="3" NAME="LNAME" xsi:type="SQLNCHAR"/>
<COLUMN SOURCE="4" NAME="PHONE" xsi:type="SQLNCHAR"/>
<COLUMN SOURCE="5" NAME="Target" xsi:type="SQLNCHAR"/>
</ROW>
</BCPFORMAT>
What I actually need: (xsi:type=”CharFixed”)
<?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="3"/>
<FIELD ID="2" xsi:type="CharFixed" LENGTH="3"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="Field1" xsi:type="SQLCHAR" LENGTH="3"/>
<COLUMN SOURCE="2" NAME="Field2" xsi:type="SQLCHAR" LENGTH="3"/>
</ROW>
</BCPFORMAT>
Here is the method I created to help me resolve my issue…