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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Exception Handling in SQL Server 2000

Author  Topic 

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2007-08-30 : 06:47:38
Hi
I am new for exception Handling in SQL Server 2000.How to handle it
i use like this for Invalid object name error user freindly.
---------------------------------------------
Declare @error int
select * from TableNotExist
set @error=@@Error
if @error<>0
print 'Table Not Exist'
else
print 'Table Exist'

-----------------------------
But above code give output

Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'TableNotExist'.


Ranjeet Kumar Singh

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-30 : 06:56:45
If exists(select * from sysobjects where name='TableNotExist' and xtype='u')
print 'Table Exists'
else
print 'Table Not Exist'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-30 : 07:09:30
replace @@ERROR with @@ROWCOUNT



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2007-08-30 : 07:10:03
Thanks
but if i write a wrong update query on any existing table and want to return @@Error value how it will done i use like this but not return
@@Error value.
Note:-Actully I want to Storing error messages in the error_log table makes it easy to trace for future.
--------------------------
Declare @error int
update tblbillentry set fltbillitemqty ='aaa'
set @error=@@Error
if @error<>0
print 'Can not convert varchar to numeric.'
else
print @error
-------------



Ranjeet Kumar Singh
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-30 : 08:02:03
www.sommarskog.se/Error-Handling-I.html
www.sommarskog.se/Error-Handling-II.html


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -