title: How to SELECT from a temp table name, passed to a stored procedure?
body: <p>I have temp table <code>name?</code> as an output from a stored procedure and I passed the <code>name</code> of created temp table to another stored procedure as an input parameter. </p>
  
  <p>I want to SELECT Guid from <code>@CalculationGuidTempTableName VARCHAR</code> then insert into <code>@CalcsGuids</code>.</p>
  
  <p>Here is my stored procedure:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[ret_Reports_ProxyVoucherAccounting]
      (@CalculationGuidTempTableName VARCHAR(32))
  AS
      DECLARE @CalcsGuids TABLE ([Guid] UNIQUEIDENTIFIER PRIMARY KEY)
  
      --INSERT INTO @CalcsGuids (SELECT * FROM  + @CalculationGuidTempTableName)
      --DROP TABLE  @CalculationGuidTempTableName
      WITH temp AS
      (
          SELECT
              reference.DetailPureTitle,
              reference.DetailCaption,
              reference.Nature,
              reference.Summarize
          FROM 
              @CalcsGuids calcs 
          INNER JOIN
              ret_vwPayrollCalculationBackPayForReport details ON details.CalculationGuid = calcs.[Guid] 
          LEFT JOIN 
              ret_PaymentAllocation payment ON payment.Guid = Details.ItemGuid 
          INNER JOIN 
              ret_vwFactorReferences reference ON reference.ItemGuid = Details.ItemGuid 
          INNER JOIN 
              ret_PayrollCalculationCommands command ON command.[Guid] =  details.CalculationCommandGuid
          WHERE
              command.Approved = 1 AND command.Deleted = 0
          GROUP BY
              reference.DetailPureTitle,
              reference.DetailCaption,
              reference.Nature,
              reference.Summarize
      )
      SELECT 
          * 
      FROM
          temp 
      WHERE 
          PayAmount &lt;&gt; 0 OR
          DeductionAmount &lt;&gt; 0 OR
          EmployerAmount &lt;&gt; 0 
      ORDER BY 
          Nature
  </code></pre>