You must create a temporary, global table with a variable-dependent name. For example:
DECLARE @TableName nvarchar(max) = 'TempTableName' CREATE TABLE ##@TableName([id] int) Creates a table named ##@TableName , not with ##TempTableName
How to create such a global temporary table?
sp_executesql, I don’t know if it is really performing the DDL, but suddenly ... - Mike