IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[xxMdTask]') AND type = 'P')
DROP PROCEDURE [dbo].[xxMdTask]
GO
CREATE PROCEDURE [dbo].[xxMdTask]
(
@ordid int
)as
begin

if  exists(select 1 from order_140_102 where ord2_ordid = @ordid  and ord2_fzcuid=272  and ord2_zt ='已完成' ) 
begin
insert into ebs_kernel.dbo.pub_message(msg_cmpid,msg_mpid,msg_text,msg_senddate,msg_type,msg_target,msg_cuid)
select 
1,
11,
'绩效组罗丹已完成！
完成时间：【'+convert(nvarchar(100),getdate(),20)+'】
单据编号：【'+ord_no+'】
详情：【'+ord2_bz+'】
{title}关店任务结清所有往来账（即时完成）',  
getdate(),
'QYH',substring(cu_qyh , 20,50) , cu_id from  mps_login,order_140,order_140_102 where cu_id=270 and  ord_id=@ordid and  ord2_fzcuid=272 andord2_ordid=@ordid
end
end