title: Pass a table variable to a SQL Server stored procedure
body: <p>I'm trying to pass a table variable to a stored procedure and I get the error:</p>
  
  <blockquote>
    <p>Operand type clash: table is incompatible with TY_MyType</p>
  </blockquote>
  
  <p>Here are the relevant pieces of code:</p>
  
  <p><strong>1 - Type Definition</strong></p>
  
  <pre><code>CREATE TYPE [dbo].[TY_MyType] AS TABLE(
          [Sampling_ID]               [int]           NULL,
          [Parameter_Name]            [nvarchar](32)  NULL,
          [Measuring_Method_Code]     [int]           NULL,
          [Greater_or_Smaller]        [varchar](1)    NULL,
          [Parameter_Value]           [float]         NULL,
          [Measured_By]               [int]           NULL,
          [No_Measurement_Code]       [int]           NULL,
          [No_Measurement_Comments]   [varchar](512)  NULL,
          [Update_Reason_Code]        [int]           NULL,
          [General_Comment]           [varchar](512)  NULL
  ) ;
  </code></pre>
  
  <p><strong>2 - Local table variable declared within the invoking procedure</strong> (there is an INSERT that injects data into this local table variable before passing it to another procedure)</p>
  
  <pre><code>DECLARE @_l_Tempo_Table TABLE ( Sampling_ID             INT             ,
                                  Parameter_Name          NVARCHAR(32)    ,
                                  Measuring_Method_Code   INT             ,
                                  Greater_or_Smaller      VARCHAR(1)      ,
                                  Parameter_Value         FLOAT           ,
                                  Measured_By             INT             ,
                                  No_Measurement_Code     INT             ,
                                  No_Measurement_Comments VARCHAR(512)    ,
                                  Update_Reason_Code      INT             ,
                                  General_Comment         VARCHAR(512)
                                ) ;
  </code></pre>
  
  <p><strong>3 - Procedure Declaration</strong></p>
  
  <pre><code>CREATE PROCEDURE [p_DATA_Save_Sampling_Results]   (
                                          @_p_Results         [UWQ].[TY_MyType] READONLY   ,
                                          @_p_Result_Code     INT             OUTPUT       ,
                                          @_p_Result_Message  NVARCHAR(2000)  OUTPUT
                                                    ) 
  AS
  :
  :
  </code></pre>
  
  <p><strong>4 - Procedure Invocation</strong></p>
  
  <pre><code>EXEC p_DATA_Save_Sampling_Results   @_l_Tempo_Table             ,
                                      @_l_Result_Code    OUTPUT   ,       -- Integer param
                                      @_l_Result_Message OUTPUT     ;     -- String
  </code></pre>
  
  <p>The invocation fails with the above mentioned error message, that appears to indicate that there is an inconsistency between the passed and the expected tables, but I can't figure out where such inconsistency could be.</p>