从CSV导入SQL Server 2005

时间:2014-03-04 17:11:07

标签: tsql sql-server-2005

每月的第一天,我将从test.csv文件信息导入到我的SQL Server 2005数据库中。我在test.csv的一栏中有这些信息:

Receiver_number|Card_Number|Lname|purchase_date|tr_verif|station_name|prod_grp|product|unit_price|vol|amount|discount|sum_no_vat|vat|sum_with_vat|country|currency|milage|origin_amount|station_id
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1003680708|704487347252000033|3|2014-02-02T19:00:00|005375|IX Fortas|01|95 Miles|3.574|109.82|474.88|-35.78|392.46|82.42|510.66|LT|LTL||510.66|65059
1003680708|704487347252000034|3|2014-02-02T19:00:00|005375|IX Fortas|24|Cola|2.893|1.00|3.50|0|2.89|.61|3.50|LT|LTL||3.50|65059

每个值都以|符号分隔。

我如何在SQL查询中获取它?

我使用过SSIS,我尝试过转换为excel并更改了计算机中的区域设置,但我可以在SQL Server 2005中获得此结果....

1 个答案:

答案 0 :(得分:0)

使用bulk insert,如下所示

BULK INSERT <your_table>
    FROM '<your_path>\test.csv'
    WITH
    (
    FIRSTROW = 2,
    FIELDTERMINATOR = '|',  
    ROWTERMINATOR = '\n',   
    ERRORFILE = 'C:\import_error.csv',
    TABLOCK
    )