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
是 啊我得到了它。非常感谢:)是的!非常感谢你。