如何在没有第一行的情况下将数据从管道分离文件导入数据库表? [英] How to import data from pipe separated file to database table without first row?

查看:69
本文介绍了如何在没有第一行的情况下将数据从管道分离文件导入数据库表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我对此查询有疑问: -



  BEGIN  
truncate table dbo.BaaN_BOM
BULK
INSERT dbo.BaaN_BOM
FROM ' C:\ OutpututFiles; \\ BOM。 txt'
WITH

FIELDTERMINATOR = ' |'
ROWTERMINATOR = ' \\ \\ n'

结束





此表中有四列。

DataBase dbo.BaaN_BOM表: - CustID(varchar(max)),CustomerName(varchar(max))地址(varchar(max))ErrorIndicator(int )



BOM.txt: - CustID |客户名称|地址| ErrorIndicator

C_001 | Raj | Noida | 1

C_002 | Jason |澳大利亚| 0

C_003 | Nathan |英格兰| 1

C_004 | Ankit |印度| 1



所以,

我想将BOM.txt中的数据填充到My dbo.BaaN_BOM表中,但我遇到ErrorIndicator

的问题,因为它是整数类型并填充了此查询中的数据,如: -



CustID客户名称地址ErrorIndicator

CustID客户名称地址ErrorIndicator

C_001 Raj Noida




我想只填充数据而不是列插入,那么,怎么可能。



请帮帮我。



在此先感谢

Ankit

软件工程师

解决方案

FIRSTROW = first_row

指定要加载的第一行的编号。默认值是指定数据文件中的第一行。 FIRSTROW是从1开始的。



注意

FIRSTROW属性不用于跳过列标题。 BULK INSERT语句不支持跳过标头。在跳过行时,SQL Server数据库引擎仅查看字段终止符,并且不会在跳过的行的字段中验证数据。



http://msdn.microsoft.com/en-us/library/ms188365.aspx [ ^ ]



更新:

我想你最好使用bcp实用程序进行数据导入。

http://msdn.microsoft.com/en-us/library/ ms175937.aspx [ ^ ]

Hello,

I have a problem with this query:-

BEGIN
truncate table dbo.BaaN_BOM
BULK
INSERT dbo.BaaN_BOM
FROM 'C:\OutputFiles\BOM.txt'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
end



Four columns in this table.
DataBase dbo.BaaN_BOM Table:- CustID (varchar(max)), CustomerName(varchar(max)) Address(varchar(max)) ErrorIndicator (int)

BOM.txt:- CustID|CustomerName|Address|ErrorIndicator
C_001|Raj|Noida|1
C_002|Jason|Australia|0
C_003|Nathan|England|1
C_004|Ankit|India|1

So,
I want to fill data from BOM.txt to My dbo.BaaN_BOM table but i have problem with ErrorIndicator
because It''s a Integer Type and filled the data from this query like:-

CustID CustomerName Address ErrorIndicator
CustID CustomerName Address ErrorIndicator
C_001 Raj Noida


I want to only data fill not column insert, So,How it can be possible.

Please help me.

Thanks in Advance
Ankit
Software Engineer

解决方案

FIRSTROW =first_row
Specifies the number of the first row to load. The default is the first row in the specified data file. FIRSTROW is 1-based.

Note
The FIRSTROW attribute is not intended to skip column headers. Skipping headers is not supported by the BULK INSERT statement. When skipping rows, the SQL Server Database Engine looks only at the field terminators, and does not validate the data in the fields of skipped rows.

http://msdn.microsoft.com/en-us/library/ms188365.aspx[^]

Update:
I guess you''d better use the bcp utility for your data import.
http://msdn.microsoft.com/en-us/library/ms175937.aspx[^]


这篇关于如何在没有第一行的情况下将数据从管道分离文件导入数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆