create table t1(name varchar(40))
insert into t1 select 'abc'
insert into t1 select 'def'
insert into t1 select 'ghi'
--創建臨時表
create table #t (ID int IDENTITY, yhm_name varchar(40))
--向臨時表中寫入數據
insert into #t
select name from t1
select @@rowcount
--取得記錄總數
declare @iRecordCount int
set @iRecordCount=@@rowcount
print @iRecordCount
--刪除測試數據
drop table #t,t1
--結果
/*
3
*/
********************************************************
聯機幫助:
@@ROWCOUNT
返回受上壹語句影響的行數。
語法
@@ROWCOUNT
返回類型
integer
註釋
任何不返回行的語句將這壹變量設置為 0 ,如 IF 語句。
示例
下面的示例執行 UPDATE 語句並用 @@ROWCOUNT 來檢測是否有發生更改的行。
UPDATE authors SET au_lname = 'Jones'
WHERE au_id = '999-888-7777'
IF @@ROWCOUNT = 0
print 'Warning: No rows were updated'
********************************************************