I'm trying to build a stored proc that allows a user to specify a table name, and then the stored proc deletes all records from that tabel. Basically I'm trying to use sp_executesql within the proc to execute a DELETE statement as shown below. I keep receiving the error "Must declare the variable '@DeleteTable'." I'm not sure what I'm doing wrong. Any ideas? Thanks!
Code:
CREATE PROCEDURE dbo.spDeleteTEMPTables
(
@TableName varchar(25)
)
AS
exec sp_executesql N'DELETE FROM @DeleteTable', N'@DeleteTable varchar(50)', @DeleteTable = @TableName
GO