title: How do I pass a table to a stored procedure?
body: <p>I am making my first attempt at creating a stored procedure (using VS2012 to edit) I am trying to pass my stored procedure a table with two columns. However when I click on parse to check my code I get the following errors.</p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Line 1<br>
    Incorrect syntax near the keyword 'AS'. </p>
    
    <p>Msg 102, Level 15, State 1, Procedure SaveMsgData, Line 10<br>
    Incorrect syntax near 'READONLY'.</p>
    
    <p>Msg 1087, Level 15, State 2, Procedure SaveMsgData, Line 45<br>
    Must declare the table variable "@tagList".</p>
  </blockquote>
  
  <p>I think the last two errors stem from the first, but I have no idea what is causing the first. As far as I can tell my syntax is correct.</p>
  
  <p>Here is my full code.</p>
  
  <pre><code>CREATE TYPE TagListType AS TABLE
  (                     
         TagID varchar(100),                
         AntNum int
  );
  GO
  
  CREATE PROCEDURE SaveMsgData 
      @Mac nvarchar(30),
      @tagList TagListType READONLY
  AS
      DECLARE @ReaderID int
      DECLARE @AntList TABLE (AntennaID int, AntNum int)
  
      SELECT @ReaderID = -1
  
      SELECT @ReaderID = Id
      FROM dbo.Readers
      WHERE MAC = @Mac
  
      IF (@ReaderID &gt;= 0)
      BEGIN
          INSERT INTO @AntList (AntennaID,Antnum,TargetNumOfTags) 
              SELECT id, AntennaNumber, numOfTags 
              FROM Antennae
              WHERE ID = @ReaderID
  
          DECLARE @count int
          DECLARE @len int                    
  
          SET @count = 0
          SET @len = 0
  
          WHILE @count &lt;= @len
          BEGIN
              DECLARE @LocalAnt int
              DECLARE @LocalTarget int
              DECLARE @LocalAntID int
              DECLARE @LocalStatus int
              DECLARE @LocalTagsRead int
  
              SELECT @LocalAnt = Antnum, @LocalTarget = TargetNumOfTags, @LocalAntID = AntID 
              FROM #AntList 
              WHERE Antnum = @count
  
              SELECT @LocalTagsRead = COUNT(*) FROM @tagList WHERE AntNum = @count
  
              IF @LocalTagsRead = @LocalTarget
              BEGIN
                  SET @LocalStatus = 0
              END
          ELSE
              BEGIN
                  SET @LocalStatus = 1
              END
  
          INSERT INTO Readings 
          VALUES (@LocalStatus, @LocalTarget, @LocalTagsRead, CURRENT_TIMESTAMP, @LocalAntID, @ReaderID)
  
          --Will insert Tags in to tag table here later.
          SET @count = @count + 1
      END
  END
  GO
  </code></pre>
  
  <p>The intent here is to have have my C# desktop application use this stored procedure.</p>