IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ChangeStatus]') AND type = 'P')
DROP PROCEDURE [dbo].[ChangeStatus]
GO

create proc [dbo].[ChangeStatus]
as
begin
/*根据客户的加盟意愿，来控制跟进情况，未及时跟进，视为放弃处理*/

/***************A级客户************************/

    /*更新主表的加盟商状态信息*/
        update n
            set n.ord_gjjg = '已放弃'               
        from order_202 n
        where n.ord_jmsyy = 'A' and DATEDIFF(day,n.ord_gjsj,GETDATE())>=3 and n.ord_gjjg = '跟进中'

 /***************B级客户************************/  
 
    /*更新主表的加盟商状态信息*/
        update n
            set n.ord_gjjg = '已放弃'
        from order_202 n
        where  n.ord_jmsyy = 'B' and DATEDIFF(day,n.ord_gjsj,GETDATE())>=3 and n.ord_gjjg = '跟进中'
    
         
 /****************C级客户***********************/   
 
      /*更新主表的加盟商状态信息*/
        update n
            set n.ord_gjjg = '已放弃'
        from order_202 n
        where  n.ord_jmsyy = 'C' and DATEDIFF(day,n.ord_gjsj,GETDATE())>=5 and n.ord_gjjg = '跟进中'
    
/****************D级客户***********************/

    /*更新主表的加盟商状态信息*/
        update n
            set n.ord_gjjg = '已放弃'
        from order_202 n
        where n.ord_jmsyy = 'D' and DATEDIFF(day,n.ord_gjsj,GETDATE())>=10 and n.ord_gjjg = '跟进中'
  end