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 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-10-23 : 08:54:13
|
| Hi,As you see below, the stored procedure inserts a record if @CountExisting = 0This is done so that no duplicates are entered into the table.The question is:How do I return an error message if the @CountExisting > 0 ?Is what I have done correct inside the else statement?Thankscreate procedure [dbo].[uspSecurityAdd]@SecurityName varchar(50)asdeclare @CountExisting tinyintbegin try select Security_Name from tblSecurities where Security_Code = @SecurityCode set @CountExisting = @@ROWCOUNT if (@CountExisting = 0) begin insert into tblSecurities ( Security_Name ) values ( @SecurityName ) end else begin RaiseError('Record already exists.') endend trybegin catch declare @msg nvarchar(200) SET @msg = ('Error during Adding Security') EXECUTE uspErrorReporter @msgend catch |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-23 : 08:56:00
|
RaiseError('Record already exists.', 16, 1) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-23 : 09:00:04
|
| www.sommarskog.se/error-handling-I.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|