By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

Error handling when calling external sql-Files

P: n/a
I am using SQL Server 2000. I have some files with SQL-Statements.

The SQL-Serveragent runs jobs which execute the SQL-Files:
(e.g. osql /E /n /i \\server\d$\lager_pool.sql)

How can I implement an error handling.

If an error occurs, the script stops, and I can't read the variable
@error

My script - table xy doesn´t exist

SELECT * FROM XY
SELECT @@error
SELECT 33

The execution stops with an error after the first line

Thanks for your help.
aaapaul

Sep 30 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi

Look at using the -b flag when you call osql, there is more information in
Books Online.

John

<lv****@gmx.net> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I am using SQL Server 2000. I have some files with SQL-Statements.

The SQL-Serveragent runs jobs which execute the SQL-Files:
(e.g. osql /E /n /i \\server\d$\lager_pool.sql)

How can I implement an error handling.

If an error occurs, the script stops, and I can't read the variable
@error

My script - table xy doesn´t exist

SELECT * FROM XY
SELECT @@error
SELECT 33

The execution stops with an error after the first line

Thanks for your help.
aaapaul
Oct 1 '05 #2

P: n/a
Thanks, but it doesn´t work

This is my script - its a file c:\test.sql

declare @errorcode int
select * from abc
SET @errorcode = @@error
--writing log
insert adaten.dbo.loghist(logdatum,loginfo,logfehler,saet ze)
values (getdate(),'test',@errorcode,25)

The table "abc" don´t exist.

If I call the script

osql /E /n /ic:\test.sql (with or without /b) the insert anweisung
instruction won´t be executed.

I want something like ON ERROR RESUME NEXT. Is this possible ?

Thanks
aaapaul

Oct 5 '05 #3

P: n/a
Hi

You may want to try using EXEC for your select statement

declare @errorcode int
EXEC ('select * from abc')
SET @errorcode = @@error
--writing log
insert adaten.dbo.loghist(logdatum,loginfo,logfehler,saet ze)
values (getdate(),'test',@errorcode,25)

John

<lv****@gmx.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Thanks, but it doesn´t work

This is my script - its a file c:\test.sql

declare @errorcode int
select * from abc
SET @errorcode = @@error
--writing log
insert adaten.dbo.loghist(logdatum,loginfo,logfehler,saet ze)
values (getdate(),'test',@errorcode,25)

The table "abc" don´t exist.

If I call the script

osql /E /n /ic:\test.sql (with or without /b) the insert anweisung
instruction won´t be executed.

I want something like ON ERROR RESUME NEXT. Is this possible ?

Thanks
aaapaul
Oct 8 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.