Sql server 批量数据源不支持SQLNUMERIC或SQLDECIMAL数据类型

Sql server 批量数据源不支持SQLNUMERIC或SQLDECIMAL数据类型,sql-server,tsql,sql-server-2008,Sql Server,Tsql,Sql Server 2008,我使用BCP导出和导入数据,但似乎不支持SQLNUMERIC或SQLDECIMAL数据类型。出口似乎很好: -- hit alt+Q then M to enable SQLCMD mode use tempdb go create table mytest (a decimal); insert mytest values (3.3); -- export to c drive !!bcp "tempdb..mytest" out "c:\mytest.dat" -T -n -S"YourSe

我使用BCP导出和导入数据,但似乎不支持SQLNUMERIC或SQLDECIMAL数据类型。出口似乎很好:

-- hit alt+Q then M to enable SQLCMD mode
use tempdb
go
create table mytest (a decimal);
insert mytest values (3.3);
-- export to c drive
!!bcp "tempdb..mytest" out "c:\mytest.dat" -T -n -S"YourServer\YourInstance" 
!!bcp "tempdb..mytest" format nul -T -n  -f "c:\mytest.fmt" -S"YourServer\YourInstance" 

GO
这很好,但当我接着将数据导入回时(如下所示):

我收到错误消息:

Msg 4838, Level 16, State 1, Line 2
The bulk data source does not support the SQLNUMERIC or SQLDECIMAL data types.
问题如何导入使用BCP导出的数字数据? 我可以控制本问题中显示的bcp命令,但不能控制表定义。首选只使用T-SQL的解决方案。

我没有使用“本机”格式,而是尝试使用字符1(“-c”),结果成功了。我使用的修改脚本是:

use tempdb 
go 
create table mytest (id int, t varchar(12), a decimal(18,2), c char); 
insert mytest values (1, 'test1', 3.6, 'a');
insert mytest values (2, 'test3', 3.3, 'b');
go 
!!bcp "tempdb..mytest" out "d:\temp\mytest.dat" -T -c -S"localhost"  
!!bcp "tempdb..mytest" format nul -T -c  -f "d:\temp\mytest.fmt" -S"localhost"  

GO 

select * from mytest

SELECT a.*  
FROM OPENROWSET(  
    BULK 'd:\temp\mytest.dat',
    FORMATFILE = 'd:\temp\mytest.fmt') AS a 

我不确定这在你的情况下是否可行,但你可以试一试。

这太棒了!而且看起来很有希望!
use tempdb 
go 
create table mytest (id int, t varchar(12), a decimal(18,2), c char); 
insert mytest values (1, 'test1', 3.6, 'a');
insert mytest values (2, 'test3', 3.3, 'b');
go 
!!bcp "tempdb..mytest" out "d:\temp\mytest.dat" -T -c -S"localhost"  
!!bcp "tempdb..mytest" format nul -T -c  -f "d:\temp\mytest.fmt" -S"localhost"  

GO 

select * from mytest

SELECT a.*  
FROM OPENROWSET(  
    BULK 'd:\temp\mytest.dat',
    FORMATFILE = 'd:\temp\mytest.fmt') AS a