SQL Server: Find out what row caused the TSQL to fail (SSIS)

前端 未结 7 1147
醉话见心
醉话见心 2021-01-13 01:57

SQL Server 2005 Question:

I\'m working on a data conversion project where I\'m taking 80k+ rows and moving them from one table to another. When I run the TSQL, it bo

7条回答
  •  广开言路
    2021-01-13 02:08

    John Sauders has the right idea, there are better ways to do this kind of processing using SSIS. However, learning SSIS and redoing your package to completely change the process may not be an option at this time, so I offer this advice. You appear to be having trouble with the dates being incorrect. So first run a query to identify those records which are bad and insert them into an execptions table. Then do you insert only of those records that are left. Something like:

     insert exceptiontable (field1, field2)
     select field1, field2 from table2 where isdate(field2) = 0
    
     insert table1 (field1, field2)
     select field1, field2 from table2 where isdate(field2) = 1
    

    Then of course you can send the contents of the exception table to the people who provide the bad data.

提交回复
热议问题