title: Operand type clash using user defined table type on SQL Server
body: <p>I have created a user defined type (with script to CREATE) given below:</p>
  
  <pre><code>CREATE TYPE [dbo].[udt_ProductID_SellingPrice] AS TABLE(
      [Product_Id] [int] NOT NULL,
      [Selling_Price] [money] NULL,
      PRIMARY KEY CLUSTERED 
  (
      [Product_Id] ASC
  )WITH (IGNORE_DUP_KEY = OFF)
  )
  </code></pre>
  
  <p>On the same database I have created a function that uses this type:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[fn_NetGP_tbl](@InputSKUs udt_ProductID_SellingPrice READONLY, @Currency VARCHAR(3), @SiteName VARCHAR(255), @CatalogueSite VARCHAR(5), @SiteGroup VARCHAR(255))
  RETURNS @Results TABLE
  (
     Product_Id INT NOT NULL,
     Selling_Price MONEY NULL,
     Net_GP MONEY NULL
  )
  AS
  BEGIN
  </code></pre>
  
  <p>I declare the Input SKUs as an in-memory table as follows and call the function as follows:</p>
  
  <pre><code>DECLARE @InputSKUs dbo.udt_ProductId_SellingPrice
  
  INSERT INTO @InputSKUs VALUES(10352316, 500.00)
  
  SELECT * FROM Sensu_Staging.dbo.fn_NetGP_tbl(@InputSKUs, 'GBP', 'Site_Name', 'SITE', 'Site_Group')
  </code></pre>
  
  <p>And get the (what I'm finding, fairly confusing) error message:</p>
  
  <blockquote>
    <p>Operand type clash: udt_ProductID_SellingPrice is incompatible with udt_ProductID_SellingPrice</p>
  </blockquote>
  
  <p>I can't really work out what I'm doing wrong - this has worked on previous databases, the only change I've made is adding a primary key/clustered index to ProductID_SellingPrice type and this seems to have thrown everything off.</p>
  
  <p>Do I need to change the function? Or is it not possible to create an index on an in-memory custom table type? We were hoping to speed the process up by indexing that table but if it's not possible then I guess we'll have to find other ways.</p>
  
  <p>Cheers,</p>
  
  <p>Matt</p>