在导入时不定义列分隔符,把所有列作为一列来处理,而在向表中插入数据时,用substring函数根据列分隔符的特征取出其中需要的部分再插入.

解决方案 »

  1.   

    if object_id('tempdb..#')is not null drop table #
    go
    create table #(a int ,b int ,c int ,d int  )  --借住臨時表處理
    bulk insert # 
    from 'E:\test.txt'
    with(
             FIELDTERMINATOR = ' ',
            ROWTERMINATOR = '\n'
            )
    if object_id('test')is not null drop table test
    go
    create table test (ID int identity(1,1),[Money] money)--目標表
    insert test select d from #
    select * from test
    /*text.txt 格式
    415 81023 240459 240652 
    415 81023 241347 241540 
    416 81024 250108 251138 
    416 81024 250108 251138 */
    /*查詢結果ID          Money                 
    ----------- --------------------- 
    1           240652.0000
    2           241540.0000
    3           251138.0000
    4           251138.0000(影響 4 個資料列)*/