Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Try/Catch error\u message()获取多个错误_Sql_Sql Server 2008_Stored Procedures_Error Handling - Fatal编程技术网

Sql Try/Catch error\u message()获取多个错误

Sql Try/Catch error\u message()获取多个错误,sql,sql-server-2008,stored-procedures,error-handling,Sql,Sql Server 2008,Stored Procedures,Error Handling,我有大约1000行的存储过程,它们构成了一个复杂的东西,我尝试使用try,catch来获取任何错误,它工作正常,但是如果脚本包含多个错误,则只检索最后一个错误,因此error_message()只获取最后一个错误 BEGIN TRY Begin Tran --Staff Commit Tran

我有大约1000行的存储过程,它们构成了一个复杂的东西,我尝试使用try,catch来获取任何错误,它工作正常,但是如果脚本包含多个错误,则只检索最后一个错误,因此error_message()只获取最后一个错误

BEGIN TRY                                                           
 Begin Tran                    
       --Staff            
Commit Tran                                                          
End Try                                                                      
        BEGIN CATCH                                           
        IF @@TRANCOUNT > 0                                                         
     select                                                                      
     error_message() as errormessage,                                                                      
     error_number() as erronumber,                                                                      
     error_state() as errorstate,                                                                     
     error_procedure() as errorprocedure,                                                                      
     error_line() as errorline;                                                                      
            ROLLBACK                                                                      
         END CATCH                                                        
  • 错误:1
  • 错误:2
  • 错误:3
select查询的结果集,仅返回错误:3

是否有任何方法可以获取所有错误,或者至少获取第一个更重要的错误

我有sql server 2008


我在这里发布之前在谷歌上搜索,找不到任何适用的解决方案

请将错误插入错误日志表。然后在退出存储过程之前,从该表中选择所有行。非常好的解决方法。