I want to display my own error message when something goes wrong in executing the below procedure rather than displaying the sqlserver error message.
Suppose in the below procedure during updation if we set value of attribute, 'userid' which already exists in the database, an error willbe raised by sqlserver as 'userid' is primary key and duplicates are not allowed. Eventhough I incorporated a sql, 'select' statement whch intimates about error and rollback the transaction , sqlserver error message is displayed rather than the 'select' statement result which intimates me about the error encounterd. Can anyone of you suggest how to override the sqlserver error message and displaying my own error message and how could we get the sqlserver raised error description.
select @flag = count(*) from admin where userid = @olduserid
IF @flag = 0
select 'failure' as result,'Admin ' + @olduserid + 'Not Found' as description
set userid = @newuserid,password = @newpassword
where userid = @olduserid and password = @oldpassword
select 'failure' as result,'Error Encountered While Modifying Admin ' + @olduserid + 'Details' as description
select 'success' as result,'' as description
I think that you've hit the same problem you did in your other thread. Because SQL Server sees the messages as a stream, you can't control their appearance at the client. The client can filter out error messages that you don't want it to display, but that's the best that I know how to do!