Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 表值参数_Sql Server_Sql Server 2008_Sql Server 2008 R2 - Fatal编程技术网

Sql server 表值参数

Sql server 表值参数,sql-server,sql-server-2008,sql-server-2008-r2,Sql Server,Sql Server 2008,Sql Server 2008 R2,我想为下表的存储过程创建表值参数 示例: All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists. 表: CREATE TABLE tabletype ( ID int identity(1,1) not null, cola varchar(10) null ); 正在创建表值参数: CRE

我想为下表的存储过程创建表值参数

示例

All queries combined using a UNION, INTERSECT or EXCEPT operator 
must have an equal number of expressions in their target lists.
表:

CREATE TABLE tabletype
(
ID int identity(1,1) not null,
cola varchar(10) null
);
正在创建表值参数:

CREATE TYPE tt as table( cola varchar(10));
正在创建存储过程:

CREATE PROC sptabletype
@tabtype tt readonly 

AS

INSERT INTO tabletype
select * from @tabtype
EXCEPT
select * from tabletype

select @@ROWCOUNT

GO 
注意:创建存储过程时出错

错误

All queries combined using a UNION, INTERSECT or EXCEPT operator 
must have an equal number of expressions in their target lists.

您的问题是
tabletype
有2列,而您的类型
tt
只有1列。正如错误所暗示的那样,yuo需要具有由查询的两个部分返回的相同数量的列。我想你想做的是:

select cola from @tabtype
EXCEPT
select cola from tabletype

看起来您的表不匹配。正如错误所说,请像下面这样写

select cola from @tabtype
EXCEPT
select cola from tabletype

是 啊我得到了它。非常感谢:)是的!非常感谢你。