Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------第二种组合
- Insert into tc_activity (actvt_id,actvt_subject,account_id,contact_id,dept_id,assigned_user_id,plan_start_time,plan_end_time
- ,start_time,end_time,actvt_multi01,create_user_id,create_time,modify_user_id,modify_time,audit_user_id,audit_time,is_audit
- ,actvt_class,actvt_priority,is_remind,remind_ahead,is_private,is_repeat,actual_cost,actvt_status,event_location,task_type
- ,audit_opinion,strVouchID,ne_approved_amount,event_address,duration)
- select distinct TOP 1
- (select max(actvt_id)+ 2 from tc_activity) as actvt_id --行动ID
- ,'新建销售订单:' + a.csocode as actvt_subject --行动主题
- ,a.cCusCode as account_id --客户编码
- ,a.ccuspersoncode as contact_id --联系人编码
- ,a.cDepcode as dept_id --部门编码
- ,a.cPersonCode as assigned_user_id --分配给USER ID (取业务员编码)
- ,a.dcreatesystime as plan_start_time --计划开始时间 (取订单制单时间)
- ,a.dcreatesystime as plan_end_time --计划结束时间 (取订单制单时间)
- ,a.dcreatesystime as start_time --开始时间 (取订单制单时间)
- ,a.dcreatesystime as end_time --结束时间 (取订单制单时间)
- ,'总金额:¥' + convert(varchar(20),(select sum(iNatSum) from SO_SODetails as b where b.id = a.id )) +
- (SELECT ',' + TotaliNatSum
- FROM (select ' ' + SO.cInvCName + '¥' +convert(varchar(20),sum(iNatSum)) + ' ' as TotaliNatSum
- from( select distinct INCL.cInvCName,SODE.iNatSum
- from SO_SODetails as SODE
- left join Inventory as INV on INV.cInvCode = SODE.cInvCode
- left join InventoryClass as INCL on INCL.cInvCCode = INV.cInvCCode
- where SODE.id = a.id
- ) as SO group by SO.cInvCName
- ) as SOD FOR XML PATH('') )
- as actvt_multi01 --沟通内容
- ,a.cPersonCode as create_user_id --创建人ID
- ,a.dcreatesystime as create_time --创建时间
- ,a.cPersonCode as modify_user_id --修改人ID
- ,a.dcreatesystime as modify_time --修改时间
- ,'' as audit_user_id --审核人ID
- ,null as audit_time --审核时间
- ,'0' as is_audit
- ,'14' as actvt_class
- ,'0' as actvt_priority
- ,'0' as is_remind
- ,'0' as remind_ahead
- ,'0' as is_private
- ,'0' as is_repeat
- ,'0.00000000' as actual_cost
- ,'3' as actvt_status
- ,'' as event_location
- ,'1' as task_type
- ,'' as audit_opinion
- ,'' as strVouchID
- ,'0.00000000' as ne_approved_amount
- ,'' as event_address
- ,'0.00000000' as duration
- from SO_SOMain as a --销售订单主表
- where a.dcreatesystime >= dateadd(day,-2,getdate())
- and a.csocode not in (select right(actvt_subject,len(actvt_subject)-7) as csocode
- from tc_activity where actvt_subject like '%新建销售订单:%') --销售订单已经建立过行动日志的,不再建立
- -------- select * from tc_activity
- -------- select actvt_id,account_id,actvt_subject,actvt_multi01 from tc_activity where actvt_subject like '%新建销售订单:%'
- -------- delete from tc_activity where actvt_subject like '%新建销售订单:%'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement