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?


Who is Participating?
devlab2012Connect With a Mentor Commented:
Change the line to:

EXEC sp_dropserver 'SvrExcel', 'droplogins'
Try terminating the line before this statement with a semi colon (;). Sometimes it is the case.
Anthony PerkinsCommented:
As previously indicated the "EXEC" is required (no point please)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.