Re: bcp problem

From: Darren Green (darren.green_at_reply-to-newsgroup-sqldts.com)
Date: 12/14/04


Date: Tue, 14 Dec 2004 15:59:41 -0000

Your data will not fit into the columns. Take your last column, it is 32
chars wide, because bcp has no concept of text qualifiers, so they are part
of the data. I assume it is tab delimited except they did not come out very
well in a newsgroup post.

You could try using a format file, where the column delimiters would be
tab + "
" + tab
tab + "

and the row delimiter is " + cr + lf.

By hand coding the column and row delimiters you can make the extra text
qualifiers be part of the delimiter and thus get stripped out.

Or

Just use DTS as it supports text qualifiers.

If you want to stick with bcp, then just try using the Bulk Insert Task, as
this has a nice format file generation option built it. The format file can
then be used with bcp instead.

-- 
Darren Green
http://www.sqldts.com
"Hans" <Hans@discussions.microsoft.com> wrote in message
news:F07776E3-8795-4A4D-930A-B42C28A9FC3C@microsoft.com...
> I posted this in Rools too, but the response rate is rather low, so here's
my
> question:
>
> I am trying to import data from a file. The file has entries like
>
> 1437 "PJ_001" 3 "PJ/001                        "
> 5746 "PJ_002" 3 "PJ/002                        "
>
> while the table is defined as
>
> k int 4 nulls
> f text 16 nulls
> c int 4 nulls
> p char 30 nulls
>
> When I use command
>
> bcp "MyDatabase.dbo.MyTable" in "D:\Development\MyDatabase\MyFile.txt" -c
> -S"MyPc\MyInstance" -U"sa" -P"MyPass"
>
> I get error message
>
> SQLState = 22001, NativeError = 0
> Error = [Microsoft][ODBC SQL Server Driver]String data, right truncation
>
> on every entry. Can anybody explain why, or even better, how to get this
> working???
>
> Thanks in advance!
> Hans.


Relevant Pages

  • Re: Create Job to dump SP results into a text file.
    ... I am glad to hear that the osql works fine now. ... I use BCP to create a format file for the output (this could be ... ', type a name to generate the format file, I use ... create a table 'authorsx' to hold the result set of the stored ...
    (microsoft.public.sqlserver.programming)
  • Re: Create Job to dump SP results into a text file.
    ... > I am glad to hear that the osql works fine now. ... > 2) using BCP to save the content of this table to a tab limited log file ... ', type a name to generate the format file, I use ... create a table 'authorsx' to hold the result set of the stored ...
    (microsoft.public.sqlserver.programming)
  • Re: BCP Troubles
    ... The SQL server we are tying to BCP into is SQL 2000. ... > way I got it to work was to run BCP and have it create a ForMaT file. ... So it sounds like the first time BCP is not executed at ...
    (comp.databases.ms-sqlserver)
  • BCP Troubles
    ... The SQL server we are tying to BCP into is SQL 2000. ... I compared the ForMat file I created by hand,to the ForMat file I ... compare to check it). ...
    (comp.databases.ms-sqlserver)
  • Re: BCP csv file only required Rows
    ... Since I use a format file to BCP only the Columns needed for BCP, ... fails the destination type column is Dateval type.So it fails. ...
    (microsoft.public.sqlserver.dts)