select top 1 * from t1 where c1='c1'
if @@rowcount=0
begin
insert t1 values('c1','c2')
end
else --如果加了 if @@rowcount>0 就不会执行update 语句(为什么????)
begin
if @@rowcount>0
update t1 set c2='c22' where c1='c1'
end
if @@rowcount=0
begin
insert t1 values('c1','c2')
end
else --如果加了 if @@rowcount>0 就不会执行update 语句(为什么????)
begin
if @@rowcount>0
update t1 set c2='c22' where c1='c1'
end
select top 1 * from t1 where c1='c1'
set @rowcnt=@@rowcountif @rowcnt=0
--...
else if @rowcnt>0
--...
else ...
if @@rowcount=0
begin
print 'if'
print @@rowcount
end
else --if @@rowcount>0
begin
print 'else'
print @@rowcount
end 显示的是 else
0
就是不明白 什么时候改变了@@rowcount的值
这句判断将其置为0.
诸如if这类不返回行的语句,都会将@@rowcount置为0.
有些还会将 @@ROWCOUNT 值设置为 1,比如DECLARE CURSOR 和 FETCH。
因此,@@rowcount要慎用。
要么就自己设置个变量 先把@@rowcount赋值一下
不然的话,指不定又出现什么状况
谢谢大家帮忙