title: Return a Table using a Scalar Valued Function in SQL Server
body: <p>I have this function and I want return the table @List.
  How I can do this? Anyone can help me.
  Thank you</p>
  
  <pre><code>ALTER FUNCTION [dbo].[GetTotalFaltasPorMes]
  (
      -- PARÂMETROS
      @UIFuncionario as char(36),
      @Data as DateTime
  )
  RETURNS TABLE
  AS
  BEGIN
      -- VARIÁVEIS
      DECLARE @TotalFaltas as float
      DECLARE @List TABLE(Jan VARCHAR(100), Fev VARCHAR(100), Mar VARCHAR(100), Abr VARCHAR(100),
                          Mai VARCHAR(100), Jun VARCHAR(100), Jul VARCHAR(100), Ago VARCHAR(100),
                          Stb VARCHAR(100), Otb VARCHAR(100), Nov VARCHAR(100), Dez VARCHAR(100)
                          );
  
      -- QUERY SQL
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='1'
      AND TpSegmento IN (6,7)
  
      SET @TotalFaltas=0
  
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='2'
      AND TpSegmento IN (6,7)
  
      INSERT INTO @List (Fev) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='3'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Mar) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='4'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Abr) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='5'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Mai) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='6'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Jun) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='7'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Jul) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='8'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Ago) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='9'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Stb) VALUES (@TotalFaltas)
  
          SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='10'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Otb) VALUES (@TotalFaltas)
  
          SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='11'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Nov) VALUES (@TotalFaltas)
  
      SET @TotalFaltas=0
      SELECT @TotalFaltas=SUM(Duracao) FROM CthAcmDiaLG
      WHERE UIFuncionario=@UIFuncionario
      AND MONTH(@Data)='12'
      AND TpSegmento IN (6,7)
      INSERT INTO @List (Dez) VALUES (@TotalFaltas)
  
      -- RETORNO
      RETURN @List
  
  END
  </code></pre>