I want to create a stored procedure that will update a table. The procedure will join two tables and I want to pass the table name using a variable (@tablename
).
This error is generated:
Must declare the table variable "@tablename".
My code:
Create Procedure dbo.SpUpdate (@TableName varchar(50))
as
begin
set @tablename='Customer'
Update a
Set AgentNumber = '5',
From dbo.CustomerList a
join @tablename b on a.customerid = b.customerid
end