sql server - Dropping tables using dynamic SQL -
i having trouble sql
stored procedure, passing in varchar()
table name using it.
my code (not working) is:
create procedure deleteuser @username varchar(50) begin --drop surf table if exists (select 1 sysobjects xtype='u' , name=@username + '_table') drop table @username + '_table' end go
however, on execution errors @ drop table @username + '_table'
line.
what doing incorrectly?
i using ms sql server 2008 if matters, called c#.
the drop table
statement can't parametrised trying. need dynamic sql.
declare @dynsql nvarchar(max) = 'drop table ' + quotename(@username + '_table'); exec(@dynsql);
Comments
Post a Comment