代码如下:


/* 创建表类型.*/
create type XTableType as table(ID int,Names varchar(10));
go

/* 创建一个存储过程以表值参数作为输入 */
create Procedure sp_test(@tp1 XTableType readonly)
as
set NoCount on
select *,getdate() from @tp1;
set NoCount off
go

/* 声明表值参数变量.*/
declare @tp2 as XTableType;

/* 将数据插入表值变量*/
Insert into @tp2(ID,Names)
select 1,'a'
union select 2,'b'
union select 3,'c';

/* 将变量传递给存储过程*/
EXEC sp_test @tp2;
go