Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

put the error on resultset

Status
Not open for further replies.

RicardoPereira

Programmer
Jun 3, 2003
255
PT
Hi,

It is possible put the print error generated by an stored procedure in a resultset?
Something like this:

Stored procedure
----------------

create procedure teste as
select * from nonexistentTabe
if (@@error <> 0)
Print 'Error on statement'


How do i put only the &quot;Error on statement&quot; in a resultset?

Thanks
Ricardo Pereira
 
You could assign the error message to a variable and then select the variable:

Declare @strError varchar(50)
set @strError = &quot;Error on Statement&quot;
select @strError as &quot;Error&quot;

mwa
<><
 
How do i assign the error to an variable?
should i do
..
if (@@error<>0)
@strError=@@error
select @strError as Error

??
This works??
 
Assign it to a variable first. Any operation sets the @@error intrinsic variable with a new value.

SELECT @error = @@error
IF @error <> 0
--you can return the error as a result set
SELECT @error

--or if you want to raise error
RAISERROR(...)

--in a sp you might want to just return the error
return @error
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top