Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-04-11 : 07:16:00
|
| Vishrant writes "Hi, Please go through the following Stored Procedure.Create Procedure stp_Test@ErrorNo int Output,@Link intas Select * from datSurvey Where Link = @Link If @@Error <> 0 Set @ErrorNo = @@ErrorThis is my Stored Procedure. I'm calling this stored procedure from VB. What i want to know is whether if an error occurs in the select statement the next line will be executed.Because when i call this from VB and passing an invalid value to @Link so that an error occurs, it is not giving me the ErrorNo which i had added to the parameters collection in VB. I'm getting a run time error. Could you please clarify.Regards,Vishrant" |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-04-11 : 09:24:57
|
| I would imagin that @@Error in this case will always be 0. I believe you're trying to determine if a business logic error occurred where by a result set of 0 is an "error". These are 2 different things. You need to check out @@ROWCOUNT. If that's 0, then you have your problem. Also I would code error handling like this: SELECT @Result_Count = @@ROWCOUNT, @error_out = @@error If @Error_Out <> 0 BEGIN Select @Error_Loc = 17 Select @Error_Type = 50001 GOTO Load_Ledger_Init_sp_Error END If @Result_Count = 0 BEGIN SELECT @Error_Loc = 18 SELECT @Error_Message = 'No Batch ID Obtained to process file 1. Check the status of the table ' + ' BATCH_CNTL' SELECT @Error_Type = 50002 GOTO Load_Ledger_Init_sp_Error ENDLoad_Ledger_Init_sp_Exit:SET NOCOUNT OFFreturn @Comp_CodeLoad_Ledger_Init_sp_Error:Rollback TRANSelect @Comp_Code = -1, @Comp_msg = @Error_Message, @Load_Ind = 'N'If @Error_Type = 50001 BEGIN Select @error_message = (Select 'Location: ' + RTRIM(Convert(char(3),@Error_Loc)) + ' @@ERROR: ' + RTRIM(Convert(char(6),error)) + ' Severity: ' + RTRIM(Convert(char(3),severity)) + ' Message: ' + RTRIM(description) From master..sysmessages Where error = @error_out) ENDIf @Error_Type = 50002 BEGIN Select @Error_Message = 'Location: ' + RTRIM(Convert(char(3),@Error_Loc)) + ' Severity: UserLevel ' + ' Message: ' + RTRIM(@Error_Message) ENDExec(@Command_String)DECLARE USER_MSG CURSOR READ_ONLY FOR select distinct user_id from user_work_profile(NoLock) Where Work_Type = 'A'-- Where User_Id = 'x057117'OPEN USER_MSGFETCH NEXT FROM USER_MSG INTO @User_IdWHILE @@FETCH_STATUS = 0 BEGIN Select @Command_String = 'Exec master..xp_cmdshell "NET SEND ' + @User_Id + ' TaxReconDB Load Failed", no_output ' Select @Command_String Exec (@Command_String) FETCH NEXT FROM USER_MSG INTO @User_Id ENDCLOSE USER_MSGDEALLOCATE USER_MSGRAISERROR @Error_Type @Error_MessageGOTO Load_Ledger_Init_sp_ExitBrett8-)Edited by - x002548 on 04/11/2003 09:25:51 |
 |
|
|
|
|
|
|
|