title: How does one use fields on a Table Type?
body: <p>Given the following SQL User-Defined Table Type:</p>
  
  <pre><code>CREATE TYPE IntegerIdTableType AS TABLE
  (
      Id INT IDENTITY NOT NULL,
      PRIMARY KEY(Id)
  );
  </code></pre>
  
  <p>How does one use the <code>Id</code> field when the type is used as a parameter in a stored procedure such as:</p>
  
  <pre><code>CREATE PROCEDURE FindPencilsForPencilCases
      @pencilCaseIds dbo.IntegerIdTableType READONLY
  AS
  BEGIN
      SELECT *
      FROM Pencils
      INNER JOIN @pencilCaseIds ON @pencilCaseIds.Id = Pencils.PencilCaseId
  END
  </code></pre>
  
  <p>I can get the above to run if I were to just run <code>SELECT * FROM @pencilCaseIds</code> but if I reference the <code>Id</code> field I instead get the following exception:</p>
  
  <pre><code>Must declare the scalar variable "@pencilCaseIds".
  </code></pre>