title: Could not allocate space for object '<temporary system object: 422212632707072>' in database 'tempdb' because the 'PRIMARY' filegroup is full
body: <p>I am trying to execute this statement but I got this error:</p>
  
  <blockquote>
    <p>Could not allocate space for object '' in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.</p>
  </blockquote>
  
  <p>SQL statement:</p>
  
  <pre><code>DECLARE
  @curvaTipicaPeriodoMes VARCHAR(50),
  @curvaTipicaPeriodoAnio VARCHAR(50),
  @curvaTipicaTipo VARCHAR(50),
  @curvaTipicaTipoInicial VARCHAR(50),
  @fronteraEstado VARCHAR(50),
  @fronteraFechaFin DATETIME,
  @birrelacion VARCHAR(50),
  @birrelacionTipo VARCHAR(50)
  
  SET @curvaTipicaPeriodoMes='10'
  SET @curvaTipicaPeriodoAnio= '2014'
  SET @curvaTipicaTipo='ValorTipico'
  SET @curvaTipicaTipoInicial='ValorTipicoInicial'
  SET @fronteraEstado='Operacion'
  SET @fronteraFechaFin = NULL
  SET @birrelacion='Bir0111'
  SET @birrelacionTipo='Tfr0005'
  
  SELECT
      Consulta.tipoDia,
      CASE WHEN Consulta.ValorTipico &gt; 0 THEN Consulta.ValorTipico ELSE Consulta.ValorTipicoInicial END AS Calculo
  FROM
     (SELECT 
          C.tipoDia,
          (SELECT (ISNULL(SUM(CC.periodo01),0) + ISNULL(SUM(CC.periodo02),0) + ISNULL(SUM(CC.periodo03),0) + ISNULL(SUM(CC.periodo04),0) + ISNULL(SUM(CC.periodo05),0) + ISNULL(SUM(CC.periodo06),0) + ISNULL(SUM(CC.periodo07),0) + ISNULL(SUM(CC.periodo08),0) + ISNULL(SUM(CC.periodo09),0) +  ISNULL(SUM(CC.periodo10),0) + ISNULL(SUM(CC.periodo11),0) + ISNULL(SUM(CC.periodo12),0) + ISNULL(SUM(CC.periodo13),0) + ISNULL(SUM(CC.periodo14),0) + ISNULL(SUM(CC.periodo15),0) + ISNULL(SUM(CC.periodo16),0) + ISNULL(SUM(CC.periodo17),0) + ISNULL(SUM(CC.periodo18),0) + ISNULL(SUM(CC.periodo19),0) + ISNULL(SUM(CC.periodo20),0) + ISNULL(SUM(CC.periodo21),0) + ISNULL(SUM(CC.periodo22),0) + ISNULL(SUM(CC.periodo23),0) + ISNULL(SUM(CC.periodo24),0)
  )
  FROM 
  [registrar].[CurvaTipica] CC 
  WHERE
  CC.tipo = @curvaTipicaTipo 
  AND CC.tipoDia=C.tipoDia
  AND
  DATEPART(MONTH,CC.periodo) = @curvaTipicaPeriodoMes 
  AND DATEPART(YEAR,CC.periodo) = @curvaTipicaPeriodoAnio 
  ) * COUNT(C.tipoDia)
  AS ValorTipico,
  (
  SELECT 
  (
  ISNULL(SUM(CC.periodo01),0) + ISNULL(SUM(CC.periodo02),0) + ISNULL(SUM(CC.periodo03),0) + ISNULL(SUM(CC.periodo04),0) + 
  ISNULL(SUM(CC.periodo05),0) + ISNULL(SUM(CC.periodo06),0) + ISNULL(SUM(CC.periodo07),0) + ISNULL(SUM(CC.periodo08),0) +
  ISNULL(SUM(CC.periodo09),0) + ISNULL(SUM(CC.periodo10),0) + ISNULL(SUM(CC.periodo11),0) + ISNULL(SUM(CC.periodo12),0) + 
  ISNULL(SUM(CC.periodo13),0) + ISNULL(SUM(CC.periodo14),0) + ISNULL(SUM(CC.periodo15),0) + ISNULL(SUM(CC.periodo16),0) +
  ISNULL(SUM(CC.periodo17),0) + ISNULL(SUM(CC.periodo18),0) + ISNULL(SUM(CC.periodo19),0) + ISNULL(SUM(CC.periodo20),0) + 
  ISNULL(SUM(CC.periodo21),0) + ISNULL(SUM(CC.periodo22),0) + ISNULL(SUM(CC.periodo23),0) + ISNULL(SUM(CC.periodo24),0)
  )
  FROM 
  [registrar].[CurvaTipica] CC 
  WHERE
  CC.tipo = @curvaTipicaTipoInicial
  AND CC.tipoDia=C.tipoDia
  AND
  DATEPART(MONTH,CC.periodo) = @curvaTipicaPeriodoMes 
  AND DATEPART(YEAR,CC.periodo) = @curvaTipicaPeriodoAnio 
  ) * COUNT(C.tipoDia)
  AS ValorTipicoInicial
  FROM [registrar].[CurvaTipica] C 
  INNER JOIN [dbo].[Frontera] F ON c.frtID=F.objID 
  INNER JOIN [dbo].[Birrelacion] B ON B.objID1=C.frtID
  WHERE
  DATEPART(MONTH,C.periodo) = @curvaTipicaPeriodoMes 
  AND
  DATEPART(YEAR,C.periodo) = @curvaTipicaPeriodoAnio 
  AND
  F.estado = @fronteraEstado 
  AND
  F.fechaFin IS NULL 
  AND
  B.objID = @birrelacion 
  AND
  B.objID2 = @birrelacionTipo
  GROUP BY 
  C.tipoDia
  ) Consulta
  ORDER BY
  Calculo
  </code></pre>
  
  <p>I checked and the tempdb is at 1400mb size and autogrowth at 10%.</p>