There are quite a few similar Questions, however i didn't quite find what i was looking for. Since using dynamic SQL in a stored procedure can quickly get cumbersome, I want to pass a table name (Varchar) to a stored procedure, turn that Tablename into a Tablevariable and afterwards work with this Tablevariable for the rest of the procedure. I can't figure out the code for this.
I'm working in SSMS on a SQL Server 2008R2. Currently my code looks similar to this. I lag the middle part to create the @Table Table Variable from the @TableName Varchar Variable
CREATE Procedure [dbo].StoredProc(@Tablename Varchar)
AS
Begin
Declare @Table Table (ColA Varchar, ColB Float)
Declare @result float
-- Something like Insert @Table Select * From @Tablename using Dynamic sql or sth. similar
Select @result = Select sum(ColB) From @Table
End