bcp导入数据为256?

时间:2011-06-29 20:21:54

标签: sql-server-2008-r2 bcp

从数据文件导入以下行时:

DATAFILE1:

1,2,3,4,5,6.789
10,11,12,13,14,15.6789

进入SQL Server 2008 R2,数据就像是将数据解释为ascii值256(即12337 =(48 * 256)+ 49,其中'0'= 48和'1'= 49)

FIELD1  FIELD2  FIELD3  FIELD4  FIELD5  FIELD6       FIELD7
49      50      51      52      53      0.00000000   NULL
12337   12593   12849   13105   13361   0.00000000   NULL

我正在使用的命令

bcp TABLE1 in DATAFILE.csv -S SERVER1 -d DB1 -U sa -f bcp.fmt

一切都成功返回而没有错误,但是当我在桌子上看时,一切都错了。这是bcp.fmt文件(非xml)

10.0
6
1       SQLINT              0       0       ","   1     FIELD1                  ""
2       SQLSMALLINT         0       0       ","   2     FIELD2                  ""
3       SQLBIGINT           0       0       ","   3     FIELD3                  ""
4       SQLBIGINT           0       0       ","   4     FIELD4                  ""
5       SQLBIGINT           0       0       ","   5     FIELD5                  ""
6       SQLDECIMAL          0       0       "\n"  6     FIELD6                  ""

表格的DDL:

CREATE TABLE [dbo].[TABLE1](
    [FIELD1] [int] NOT NULL,
    [FIELD2] [smallint] NOT NULL,
    [FIELD3] [bigint] NOT NULL,
    [FIELD4] [bigint] NULL,
    [FIELD5] [bigint] NULL,
    [FIELD6] [decimal](18, 8) NOT NULL,
    [FIELD7] [decimal](18, 8) NULL
)

1 个答案:

答案 0 :(得分:1)

终于找到了答案: http://www.codeproject.com/Messages/3531341/bcp-and-int-ASCII-code-conversion-modified.aspx

问题出在bcp.fmt文件中。应指定数据类型。引用其中一个回答“只是将该死的字段标记为SQLCHAR,并让db进行转换并且一切正常。”