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 |
richardps
Starting Member
33 Posts |
Posted - 2007-03-23 : 05:28:21
|
Hi,I call a .sql file from a batch file using OSQL. Within the .sql file I'm executing a cursor with a "grant select..." in a loop.If any of these grants fail due to Msg 208 (Invalid Object Name) I need the cursor to continue, and once it's finished, I need the remainder of my .sql to be executed. So, to put it another way I need to handle that one error.I was thinking the best way would be to implement an "IF @@ERROR.." after the grant line but I'm not entirely sure how to do this and also whether A) my cursor will continue and B) the remainder of the .sql will continue and not return a error to the calling OSQL.Your assistance is appreciated.Thanks,Richard. |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-23 : 05:37:31
|
Why do you want to wait for error to happen and react? Why not first check for the existence of an object and if it exists, then perform further processing.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
richardps
Starting Member
33 Posts |
Posted - 2007-03-23 : 06:00:21
|
Hi,Thanks for your reply. Unfortunately I am checking for existence (from sysobjectswhere XTYPE = 'V') and thus creating the cursor but another job can (very rarely) run simultaneously and delete and recreate the views. There are hundreds of views.Thanks again,Richard |
 |
|
richardps
Starting Member
33 Posts |
Posted - 2007-03-23 : 06:23:42
|
Allow me to clarify my questions:1) When a MSG 208 is encountered in a cursor loop, does the loop continue and complete or does it exit immediately at that point. I think it continues.2) How do I stop the .sql returning an ERROR to the calling OSQL? (In particular if the error is 208 and occurred in the cursor)Thanks,Richard. |
 |
|
|
|
|