IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_pub_prg_form]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_pub_prg_form]
GO
 
CREATE procedure [dbo].[mps_g_pub_prg_form](
@cmpid int ,
@branchid int,
@userdpid int,
@useruid int ,
@userotid int,
@useradmin int,
@program varchar(50) 
) as
begin
set nocount on
declare @ptid int 
set @ptid = 0 
select top 1 @ptid = pt_id  from mps_programtype 
where pt_cmpid=@cmpid and pt_program=0 and pt_filename=@program 
if (@ptid>0) 
begin
-- 先查出缺省值那一条
select * from mps_template where tmp_cmpid=@cmpid and 
tmp_type='prg' and tmp_objid=@ptid and tmp_objid2=0 
-- 再查一下有没有当前角色的
if (exists (select 1 from mps_template where tmp_cmpid=@cmpid and 
tmp_type='prg' and tmp_objid=@ptid and tmp_objid2=@useradmin))  
begin
select * from mps_template where tmp_cmpid=@cmpid and 
tmp_type='prg' and tmp_objid=@ptid and tmp_objid2=@useradmin
end 
end  
set nocount off 
end