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-07-02 : 08:00:34
|
| Daniel writes "I'm trying to return to an ASP from a stored proc the specific error message that belongs to an error code that is non-zero subsequent to performing an insert.I found (in The Guru's Guide to Transact-SQL manual) what I believe to be the exact text error message when an insert returns a non-zero result. Consequently, I thought of creating a case statement that will set the text corresponding to the code.However, I can not seem to get this code to work. Here is the section of code that is not working:IF (RTRIM(@FILENAME) <> '') BEGIN INSERT TBL_FILE (ITEM_ID, filename, DESCRIPTION, SIZE_K, CREATED)VALUES (@ITEM_ID, @FILENAME, @DESC, @FILESIZE, GETDATE())set @RetVal = @@ERRORIF (@RetVal <> 0) BEGINset @error_text = CASE @RetValWHEN -1 THEN 'Object Missing'WHEN -2 THEN 'Data type error occurred'WHEN -3 THEN 'Process chosen as deadlock victim'WHEN -4 THEN 'Permission error'WHEN -5 THEN 'Syntax error'WHEN -6 THEN 'Miscellaneous user error'WHEN -7 THEN 'Resource error'WHEN -8 THEN 'Non fatal internal error'WHEN -9 THEN 'System limit reached'WHEN -10 THEN 'Fatal internal inconsistency error'WHEN -11 THEN 'Fatal internal inconsistency error'WHEN -12 THEN 'Corrupt table or index'WHEN -14 THEN 'Hardware error'ELSE 'Undefined error: Could not add file to database'ROLLBACK TRANSACTIONENDELSE BEGINCOMMIT TRANSACTIONSET @ERROR_TEXT = 'File Added to Database'ENDENDWhen I check the syntax in Query Analyzer, I get the error message:Incorrect syntax near the keyword "ROLLBACK"I can't figure out what's wrong with this CASE statement." |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-07-02 : 08:02:51
|
| Your CASE expression was not ended properly:IF (@RetVal <> 0) BEGIN set @error_text = CASE @RetVal WHEN -1 THEN 'Object Missing' WHEN -2 THEN 'Data type error occurred' WHEN -3 THEN 'Process chosen as deadlock victim' WHEN -4 THEN 'Permission error' WHEN -5 THEN 'Syntax error' WHEN -6 THEN 'Miscellaneous user error' WHEN -7 THEN 'Resource error' WHEN -8 THEN 'Non fatal internal error' WHEN -9 THEN 'System limit reached' WHEN -10 THEN 'Fatal internal inconsistency error' WHEN -11 THEN 'Fatal internal inconsistency error' WHEN -12 THEN 'Corrupt table or index' WHEN -14 THEN 'Hardware error' ELSE 'Undefined error: Could not add file to database' ENDROLLBACK TRANSACTION ENDELSE BEGIN COMMIT TRANSACTION SET @ERROR_TEXT = 'File Added to Database' END |
 |
|
|
|
|
|