August 1, 2005 at 1:42 am
hi
can anybody tell me y this query works
IF EXISTS (SELECT SRVNAME FROM master..sysservers WHERE SRVNAME='db1' ) exec sp_dropserver 'db1', 'droplogins'
and this fails
IF EXISTS (SELECT SRVNAME FROM master..sysservers WHERE SRVNAME='db1' ) sp_dropserver 'db1', 'droplogins'
thanks
Amrita
August 1, 2005 at 1:58 am
The second query is missing the exec keyword. But I assume you already knew that, since that is the only differemce between them. I do not know how to answer the question other than that the exec keyword is required in that context.
August 1, 2005 at 2:01 am
Here is the relevant text from BOL:
You do not have to specify the EXECUTE keyword when executing stored procedures if the statement is the first one in a batch.
Since the statement is not the first one in the batch (the if part preceeds it) you have to specify EXEC[UTE].
August 1, 2005 at 2:03 am
In the second query, you might be getting this error "Incorrect syntax near 'sp_dropserver'"..
This is because, "You can execute a stored procedure without using the EXEC keyword if the stored procedure is the first statement in the batch." i.e. if your first statement is sp_Dropserver then no use of using Exec since you are using it in a if-else condition you have to use the exec keyword..
HTH
Regards,
Dilip
August 1, 2005 at 2:12 am
ya that makes sense , thnx for all the help
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply