You'll have to create a SQL statement and execute it using sp_executesql. This adds the additional difficulty that temporary tables created via a dynamic execution exist only in the context of that execution. Your table will need to be a global temporary table using ## rather than #.
CREATE PROC proctestSearch
@name varchar(61) =null
AS
declare @sql nvarchar(1000), @tname nvarchar(40)
set @tname='##temptbl'
Set @sql='Select * Into ' + @tname +
' From Maintbl Where myname = @name'
sp_executesql @sql,N'@name varchar(61)',@name
drop table ##temptbl
I have to ask why you want to input the temporary table name as a variable and add this complexity to the procedure. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.