如何更新列的所有行

时间:2014-04-30 12:01:14

标签: sql-server-2008 tsql

我正在尝试更新一列上的多行(SQL Server 2008)。我需要更新的列有插入和更新触发器。当我运行此脚本时,我收到一条错误消息:

 UPDATE htable
    SET Isverified=1
  WHERE columnname IN ('122','566','652')

错误:

  

Msg 512,Level 16,State 1,Procedure mydatabasename,Line 22
  子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。

我不知道这是多么真实,但我想相信由于此列上的触发器定义。有没有人想知道如何实现这一目标  这是触发器:

ALTER TRIGGER [dbo].[sendTodbase]
ON  [dbo].[htable]
AFTER UPDATE
AS 
BEGIN DISTRIBUTED TRANSACTION
SET NOCOUNT ON
--CHECK IF DATAENTRY COLUMN IS UPDATED
IF UPDATE(Isverified) begin
declare @dEVer bit declare @rcNum varchar(50) 
declare @idenNum varchar(50) declare @docId bigint

--GET INSERTED VALUE AND CHECK IF IT's (YES) THEN CONTINUE...
select @dEVer = (select Isverified from inserted i)
if @dEVer = 1 begin
--END CHECK, IF DE IS COMPLETED CONTINUE----

COMMIT TRAN

2 个答案:

答案 0 :(得分:2)

异常可能是由:

生成的
select @dEVer = (select Isverified from inserted i)

TSQL解释器期望select Isverified from inserted i子查询返回的行不超过一行。

您的update查询会生成多行,并生成例外Subquery returned more than 1 value

答案 1 :(得分:0)

尝试这样的事情:

Update mydatble set ColumnName = <Require value>
where columnname in ('122','566','652')