これはif @i=0
それを0に設定し、printステートメントでも0に設定します
今これを実行します
declare @i int, @RowNum int
set @i=0
while @i<2
begin
if @i=0
begin
execute StoredProcedure @i --containing a big select
set @RowNum=@@rowcount
end
else
execute StoredProcedure @i
set @i=@i+1
end
print @RowNum
これは別の例です
select 1
union all
select 2
select @@rowcount --2
go
今は0になります
select 1
union all
select 2
if 1=1
select @@rowcount --0
PRINTもそれを台無しにします、これは2になります
select 1
union all
select 2
select @@rowcount --2
go
これは0になります
select 1
union all
select 2
print '1'
select @@rowcount -- 0
ここに、より多くの例と説明を含む投稿を作成しました。@@ ROWCOUNTを変数に格納する必要があるのはいつですか?