2008 SQL Server bulk insert data error

        A few days ago when the SQL Server 2008 product data synchronization, always prompt error binary text is truncated, but after examination found that the data are consistent format requirements.

Puzzling, a single insert can be inserted into the pieces of data, but the error introduced into the batch.

        Bulk import code examples are as follows:

       Table associated SELECT * into #product from a series of

        where certain conditions

        ...

        insert into t_product

        select * from #product

        Finally, under the helpless read cycle insertion cursor:

---使用游标测试插入过程
 DECLARE Prod_Cursor Cursor Local For
 SELECT ProdCode_SAP FROM #Product
 
 OPEN Prod_Cursor
 DECLARE @ProdCode_SAP nvarchar(20) 
 FETCH NEXT FROM Prod_Cursor INTO @ProdCode_SAP
 
 WHILE @@FETCH_STATUS=0
 BEGIN
  
  BEGIN TRY
  INSERT INTO t_Product(。。。)
    SELECT 。。。 FROM #Product 
    where ProdCode_SAP=@ProdCode_SAP
   END TRY
   BEGIN CATCH
    print @ProdCode_SAP
   END CATCH
 

 IF EXISTS(SELECT 1 FROM  t_Identity WHERE TableName='t_Product')
  UPDATE  t_Identity SET CurrNo=@ProdID WHERE TableName='t_Product'
 else 
  。。。。

  FETCH NEXT FROM Prod_Cursor INTO @ProdCode_SAP
  
 END
 
 CLOSE Prod_Cursor
 DEALLOCATE Prod_Cursor
 
 drop table #Product

 

But the unexpected is now solved the problem, but why it is not in accordance with the above bulk insert, you can do the following?

The reason has yet to find. . .

 

Reproduced in: https: //www.cnblogs.com/kevinGao/p/3264246.html

Guess you like

Origin blog.csdn.net/weixin_33884611/article/details/93051535