Link to home
Start Free TrialLog in
Avatar of jruhe
jruheFlag for United States of America

asked on

sql error on sp_dropserver while running whole query or debugging, but not when executing the individual line

In SQL Server 2008, I hae the following line just before adding the linked server back:

sp_dropserver 'SvrExcel', 'droplogins'

I realize I could check for the existence of SvrExcel, but this named server always exists for me because whenever I do one of many small data manipulation jobs, I overwrite it with the next one.  I get the following message when I run it by executing the whole sql query, and also when I use the debug feature.  

Msg 102, Level 15, State 1, Line 19
Incorrect syntax near 'sp_dropserver'.

However, I do not get the error message, and the command is successful, when I merely select the line and execute the one line.

Any clue as to why it would be showing an error while executing the whole query but not when executing the one line?

TIA

jr
ASKER CERTIFIED SOLUTION
Avatar of devlab2012
devlab2012
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try terminating the line before this statement with a semi colon (;). Sometimes it is the case.
Avatar of Anthony Perkins
As previously indicated the "EXEC" is required (no point please)