2

You are thinking about the problem the wrong way.
You can use dynamic SQL to do this - by defining your result shape within the statement, but creating the temporary table outside of it. Like so:
CREATE PROC test @var1 CHAR(1)
as
BEGIN
-- USING dynamic sql
DECLARE @sql VARCHAR(MAX)
IF(@var1 =...