1.返回表中的记录数
CREATE procedure sp_table_count(@pi_table_name varchar(64))
as
DECLARE @l_select_sql nvarchar(1000)
DECLARE @count int
SET @l_select_sql = 'select @c=count(1) from ' + @pi_table_name
EXEC sp_executesql @l_select_sql, N'@c int output', @count OUTPUT
SELECT @count AS cnt
调用
EXEC sp_table_count 'tb_dic_class'
记录数作为输出参数返回
CREATE procedure sp_table_count01(@pi_table_name nvarchar(64),@po_record_count int out)
as
begin
DECLARE @l_select_sql nvarchar(1000)
SET @l_select_sql = 'select @po_record_count=count(1) from ' + @pi_table_name
EXEC sp_executesql @l_select_sql, N'@po_record_count int output',@po_record_count OUTPUT
end
调用
DECLARE @l_record_cnt int
EXEC sp_table_count01 'tb_dic_class', @l_record_cnt output
SELECT @l_record_cnt
阅读(3698) | 评论(0) | 转发(0) |