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 - 2011-11-08 : 05:53:33
|
| Hi,This is briefly what I have in my stored proc.create procedure uspTestasbegin tryset nocount on...if (select count(*) from tblMain) > 0 begin --some processing... endelse begin -------?????---------------------------- --to shown an error message i.e. no data found. -- how is this raised to the user? -------?????---------------------------- endset no count offend trybegin catch declare @msg nvarchar(200) SET @msg = ('Error during xxx process...') EXECUTE uspError @msgend catch |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-08 : 05:56:46
|
| Is there a question here?My error handling is usuallybegin catchdeclare @ErrDesc varchar(max) = coalesce(ERROR_MESSAGE(),'<null>')declare @ErrProc varchar(500) = coalesce(ERROR_PROCEDURE(),'<null>')declare @ErrLine varchar(100) = coalesce(ERROR_LINE(),'<null>')declare @ErrorNo varchar(100) = coalesce(ERROR_NUMBER(),'<null>') insert Trace (Entity, key1, data1, data2) select Entity = @entity, key1 = 'Failure', data1 = '<ErrProc=' + @ErrProc + '>' + '<ErrLine=' + @ErrLine + '>' + '<ErrDesc=' + @ErrDesc + '>' , data2 = '<SQLErrorNo=' + @ErrorNo + '>' raiserror('Failed %s', 16, -1, @ErrDesc)end catch@entity has already been set to OBJECT_NAME(@@procid)but it's up to you==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-11-08 : 06:32:56
|
| -------?????---------------------------- --to shown an error message i.e. no data found.-- how is this raised to the user?-------?????---------------------------- |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-08 : 06:50:00
|
quote: Originally posted by arkiboys -------?????---------------------------- --to shown an error message i.e. no data found.-- how is this raised to the user?-------?????----------------------------
capture @msg value as a output parameter and show it in your applicationhttp://www.sqlteam.com/article/stored-procedures-returning-data------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-08 : 07:02:39
|
| You could just do a raiserror and it will be caught be the try catch block. Is it an error or just information though.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-11-08 : 07:19:26
|
quote: Originally posted by nigelrivett You could just do a raiserror and it will be caught be the try catch block. Is it an error or just information though.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
It is just information |
 |
|
|
|
|
|
|
|