IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_sys_calc_prdpower_data_all]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_sys_calc_prdpower_data_all]
GO
create  procedure [dbo].[mps_sys_calc_prdpower_data_all](
@cmpid int 
) as
begin
declare c1 cursor LOCAL FORWARD_ONLY READ_ONLY for
select pc_id  from mps_prdctg  where pc_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 
set @mctid = @bizid * (-1) 
exec sys_sql_getTableNamePk @cmpid,'prd',@mctid,0,@tbname output,@fkey output ,@dbname output 
set @tbname = @dbname + @tbname
exec mps_sys_checktable @tbname , @tableexists1 output 
set @tbname = @tbname+'_users' 
exec mps_sys_checktable @tbname , @tableexists2 output 
if (@tableexists1=0 and @tableexists2=0) 
 exec mps_sys_calc_prdpower_data @cmpid,@bizid 
 FETCH NEXT FROM c1 INTO @bizid 
END
CLOSE c1
DEALLOCATE c1 
end