sql server table type clash operand

You're come up against one of the limitations of the user defined table type.

See this Microsoft Connect item, closed as "as-designed".

The reasoning given is that

  1. The [table]type of the proc param must be exactly the type of the incoming param
  2. It becomes increasingly expensive to validate if rule (1) were not applied

It is impossible to pass table-type parameters between databases, because you cannot use code like

create proc PROC2( 
 @myVar db1.dbo.myCustomType READONLY
)

The error is:

The type name 'db1.dbo.myCustomType' contains more than the maximum number of prefixes. The maximum is 1.

Just because you named them the same and gave them the same definition in both DB1 and DB2 does not make them the same type - they remain incompatible, as much as the below which also fails on a single db:

CREATE TYPE myCustomTypeX AS TABLE
(
somevalue INT, 
somevalue2 INT
);
GO
create proc procX
@in myCustomTypeX readonly
AS
select * from @in myCustomTypeX;
GO
declare @myCustomTypeX TABLE
(
somevalue INT, 
somevalue2 INT
);
exec procX @myCustomTypeX

--
Msg 206, Level 16, State 2, Procedure procX, Line 0
Operand type clash: table is incompatible with myCustomTypeX

I'm using SQL Server 2012 on both databases and this limitation still applies.

There's a great article here full of workarounds: http://www.sommarskog.se/share_data.html

For my immediate problem I've gone with XML to pass a table of data from one proc to another. It's clunky, but I only have to pass a couple of dozen records at a time. Many more than that and I'd start to worry about performance.