存储过程中怎样计算表的行数

来源:百度知道 编辑:UC知道 时间:2024/06/02 05:04:35
请给个简单的示例。比如说有个表
notice,有ID,Name两个列。
现在往里面添加了一些值。如
ID,Name
1,刘欢,
2,黎明,
3,张学友
想写一个存储过程中,获取该表的行数。该怎么写啊

select count(ID) from notice

declare @count int
select @count = count(*) from aaa
取的时候 @count 就是行数

执行语句结束后的@@RowCount代表操作影响的行数

Create Proc linecount--新建存储过程
@count int output--输出参数
as
select @count=count(*) from notice--统计赋值

--调用
declare @a--声明变量@a
execute linecount @a output--调用存储过程
print @a--输出变量@a

够详细吧

create proc count_sp
@num int output
as
begin
select * from notice

set @num=@@rowcount
end