我参照网络资料写了个存储过程,怎么加入条件判断,比如name like '%公司%'???我贴我的存储过程
set nocount on
if object_id(N'tempdb.db.#temp') is not null
drop table #temp
create table #temp (name sysname,count numeric(18))
insert into #temp
select o.name,i.rows
from sysobjects o,sysindexes i
where o.id=i.id and o.Xtype='U' and i.indid<2
select * from #temp
set nocount off
1:首先创建两张表
--create table FFF1 (id int)
--create table FFF_SUM(name2 char(50),id int)
2:创建存储过程
create proc tFFF_SUM
As
select identity(int,1,1)as id ,name as name1
into #a
from sysobjects where xtype='U' --把
查询的表放到临时表中
declare @total int,@i int,@count Int,@name char(50),@aa varchar(200) --定义一些变量
set @i=1
select @total=count(*) from #a --获得总表数
while @i<@total+1 --循环次数
begin
delete from FFF1 --清空上次的比数
select @name=name1 from #a where id=@i --循环得到表的名字
set @aa='select count(*) from ' +QUOTENAME(@name) --动态执行语句
insert into FFF1
exec(@aa) --把表的记录数方法哦表FFF1中
set @i=@i+1
select @count=id from FFF1 --把数量赋值给变量@count
inSERT INTO FFF_SUM
select @name,@count -- 把表名和记录数放到表FFF_SUM 中
end
--select *from FFF_SUM 存储过程执行完 查询每张表的情况
--最好先用用户表少的数据库来测试