title: HOW TO CREATE TEMP TABLE USING stored procedure
body: <p>I want to create a stored procedure in SQL Server 2012 that returns a temp table.</p>
  
  <p>My code is</p>
  
  <pre><code>CREATE PROC [dbo].[aac_trial_balance_data]
      @company_code char(5),
      @target_level int,
      @StartDate char(12),
      @EndDate char(12)
  AS
  BEGIN
      SELECT
          dbo.getParentCode(chart_code,@target_level,LEVEL) chart_code,
          level,
          SUM(debit) debit, 
          SUM(credit) credit
      FROM
          acc_trial_balance_vw 
      WHERE
          convert(datetime, create_date, 103) between convert(datetime, cast(@StartDate as datetime), 103) 
                                                  and convert(datetime, cast(@EndDate as datetime) + '23:59:59', 103)  
          AND company_code = @company_code 
      GROUP BY 
          chart_code, LEVEL 
  END
  </code></pre>
  
  <p>I want to create a Temp table after the query like </p>
  
  <pre><code>CREATE PROC [dbo].[aac_trial_balance_data]
      @company_code char(5),
      @target_level int,
      @StartDate char(12),
      @EndDate char(12)
  AS
  BEGIN
      (select 
              dbo.getParentCode(chart_code,@target_level,LEVEL) chart_code,
              level,
              SUM(debit) debit, 
              SUM(credit) credit
          from acc_trial_balance_vw 
          where 
          convert(datetime,create_date,103) between convert(datetime, cast(@StartDate as datetime) , 103) 
          and  convert(datetime, cast(@EndDate as datetime)+'23:59:59' , 103)  
          and company_code = @company_code 
           GROUP BY chart_code, LEVEL 
           )
           AS
           #TEMP-TABLE -- This is my Temp Table That i want to create
  END
  </code></pre>
  
  <p>How can id do it </p>