Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

executing a test in sql server 2005

When I am executing following ...

EXEC 'DROP TABLE bkp_anish_test'

('DROP TABLE bkp_anish_test' is a dynamically build sql query)

I am getting following error

Could not find stored procedure 'DROP TABLE bkp_anish_test'.

like image 482
Relativity Avatar asked Dec 13 '10 03:12

Relativity


2 Answers

Do this instead:

exec sp_executesql N'DROP TABLE bkp_anish_test'

or for the case of a dynamically built string:

declare @MyTable nvarchar(100)
set @MyTable = N'bkp_anish_test'

declare @sql nvarchar(100)
set @sql = N'DROP TABLE ' + @MyTable
exec sp_executesql @sql
like image 81
Joe Stefanelli Avatar answered Oct 29 '22 21:10

Joe Stefanelli


Try adding parentheses to your command. You must include them when running a SQL statement, if you're going to use the EXEC command.

EXEC ('DROP TABLE bkp_anish_test')
like image 45
bobs Avatar answered Oct 29 '22 22:10

bobs