I am using bcp
utility to import data into Sybase
database on Solaris
system
Since the bcp file is generated by another xml pa
Sybase format files can be tricky to use, and I have yet to get them to work to redorder columns. Without a format file, and since you can not control the input file you're given, your options are:
bcp
in, and move the data into your production table from there.Given your data format, the following bcp
command line should work.
bcp DBNAME..TABLENAME in MY_FILE.bcp -U username -P password -S SERVERNAME -c -t\| -r\\n
As most of the loader utilities, BCP does not read rows, it just gets a bunch of bytes from the source file, therefore, you have to specify the end line character on the .fmt file mostly when the end of line character can be different depending on the encoding of the file.
For example, in the example you provided, you have this on the source file:
603289|Aug 20 2011 12:00AM|YYY aaa OVD|KLYYP8
603284|Aug 22 2011 12:00AM|XXX bbb OVD|KLPK06
But depending on the Encoding you will have this:
603289|Aug 20 2011 12:00AM|YYY aaa OVD|KLYYP8\n603284|Aug 22 2011 12:00AM|XXX bbb OVD|KLPK06
or this:
603289|Aug 20 2011 12:00AM|YYY aaa OVD|KLYYP8\n\r603284|Aug 22 2011 12:00AM|XXX bbb OVD|KLPK06
That's why the change of the terminator you did on the last column is so important:
10.0
4
1 SYBCHAR 0 12 "|" 3 ver
2 SYBCHAR 0 26 "|" 2 first_dt
3 SYBCHAR 0 60 "|" 4 name1
4 SYBCHAR 0 10 "\n" 1 name2 * The last terminator was not "|"
The following image shows what means each component on the format file (I got it from here):