I want to create a stored procedure in which I have a sourcetable
input parameter and I want to use delete statement to delete rows from a destination table corresponding to that source table value, e.g.:
Create proc spdeleteRows
@sourcetable varchar(50)
As
Begin
Declare @destname varchar(50)
Select @destname = destname from tblConfig where sourcetable=@sourcetable
Delete from @destname where convert(date,loaddate) =getdate();
End
How do I do it?
It shows error at @destname
since it is declared as varchar but I cannot declare it as table variable since I will also have to define its structure as well which will be dynamic.
Please help.