IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_sys_calc_rptpower_all]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_sys_calc_rptpower_all]
GO
create procedure [dbo].[mps_sys_calc_rptpower_all](
@cmpid int 
) as
begin
declare @userchanged int 
select @userchanged=COUNT(1) from mps_tableupdated where tu_cmpid=@cmpid and tu_table in ('mps_employee','mps_depart') and tu_updated=0 
declare c1 cursor LOCAL FORWARD_ONLY READ_ONLY for
select rpt_id  from mps_report  where rpt_cmpid=@cmpid  
open c1
declare @bizid int 
declare @tableexists1 int
declare @tableexists2 int
declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50)
declare @mctid int 
FETCH NEXT FROM c1 INTO @bizid 
WHILE (@@FETCH_STATUS = 0)
BEGIN
set @tableexists1 = 1 
set @tableexists2 = 1 
exec mps_sys_calc_rptpower @cmpid,@bizid 
 FETCH NEXT FROM c1 INTO @bizid 
END
CLOSE c1
DEALLOCATE c1 
end