Reputation: 6868
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'.
Upvotes: 6
Views: 111
Reputation: 1173
You dont need to use EXEC to run the sql statement. In the query editor, just run
DROP TABLE bkp_anish_test
if the table is in xyz database, try this
EXEC ('USE xyz ; DROP TABLE bkp_anish_test;');
Upvotes: 0
Reputation: 22224
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')
Upvotes: 1
Reputation: 135928
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
Upvotes: 2