Declare @tb table([id] int);
insert into @tb([id])
select [id] from [table] where [flag]=0;
update a set [flag]=1 From [table] as a join @tb as b on a.[id]=b.[id];
select a.* from [table] as a join @tb as b on a.[id]=b.[id];
1,从某表中选择出flag为0的记录 2,并将所选数据中的FLAG字段变为1 平时我的语句如下 Declare @tb table([id] int); insert into @tb([id]) select [id] from [table] where [flag]=0; update a set [flag]=1 From [table] as a join @tb as b on a.[id]=b.[id]; select a.* from [table] as a join @tb
Declare @tb table([id] int);
insert into @tb([id]) select [id] from [table] where [flag]=0;
update a set [flag]=1 From [table] where flag = 0;
select a.* from [table] as a join @tb as b on a.[id]=b.[id];
Declare @tb table([id] int);
insert into @tb([id]) select [id] from [table] where [flag]=0;
update a set [flag]=1 From [table] where flag = 0;
select a.* from [table] as a join @tb as b on a.[id]=b.[id];
Declare @tb table([id] int);
insert into @tb([id]) select [id] from [table] where [flag]=0;
update a set [flag]=1 From [table] where flag = 0;
select a.* from [table] as a join @tb as b on a.[id]=b.[id];
[/Quote]
能具体点吗?
你这样写会不会出现。你插入@tb的时候有n条记录,而更新的时候却更新了n+1条记录,而最后你又只选择了n条记录的情况发生呢?
Declare @tb table([id] int);
insert into @tb([id]) select [id] from [table] where [flag]=0;
update a set [flag]=1 From [table] where flag = 0;
select a.* from [table] as a join @tb as b on a.[id]=b.[id];