Advertisement
Pandaaaa906

Untitled

Sep 9th, 2022
1,418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.95 KB | None | 0 0
  1. ------------------第二种组合
  2.  
  3. Insert into tc_activity (actvt_id,actvt_subject,account_id,contact_id,dept_id,assigned_user_id,plan_start_time,plan_end_time
  4. ,start_time,end_time,actvt_multi01,create_user_id,create_time,modify_user_id,modify_time,audit_user_id,audit_time,is_audit
  5. ,actvt_class,actvt_priority,is_remind,remind_ahead,is_private,is_repeat,actual_cost,actvt_status,event_location,task_type
  6. ,audit_opinion,strVouchID,ne_approved_amount,event_address,duration)
  7.  
  8. select distinct TOP 1
  9.  (select max(actvt_id)+ 2 from tc_activity) as actvt_id --行动ID
  10. ,'新建销售订单:' + a.csocode as actvt_subject --行动主题
  11. ,a.cCusCode as account_id --客户编码
  12. ,a.ccuspersoncode as contact_id --联系人编码
  13. ,a.cDepcode as dept_id --部门编码
  14. ,a.cPersonCode as assigned_user_id --分配给USER ID (取业务员编码)
  15. ,a.dcreatesystime as plan_start_time --计划开始时间 (取订单制单时间)
  16. ,a.dcreatesystime as plan_end_time --计划结束时间 (取订单制单时间)
  17. ,a.dcreatesystime as start_time --开始时间 (取订单制单时间)
  18. ,a.dcreatesystime as end_time --结束时间 (取订单制单时间)
  19. ,'总金额:¥' + convert(varchar(20),(select sum(iNatSum) from SO_SODetails as b where b.id = a.id ))  +
  20.  (SELECT ',' + TotaliNatSum
  21.   FROM (select ' ' + SO.cInvCName + '¥' +convert(varchar(20),sum(iNatSum)) + ' ' as TotaliNatSum  
  22.         from( select distinct INCL.cInvCName,SODE.iNatSum
  23.               from SO_SODetails as SODE
  24.               left join Inventory as INV on INV.cInvCode = SODE.cInvCode
  25.               left join InventoryClass as INCL on INCL.cInvCCode = INV.cInvCCode
  26.               where SODE.id = a.id
  27.             ) as SO group by SO.cInvCName
  28.         ) as SOD FOR XML PATH('') )
  29.  as actvt_multi01 --沟通内容
  30. ,a.cPersonCode as create_user_id --创建人ID
  31. ,a.dcreatesystime as create_time --创建时间
  32. ,a.cPersonCode as modify_user_id --修改人ID
  33. ,a.dcreatesystime as modify_time --修改时间
  34. ,'' as audit_user_id --审核人ID
  35. ,null as audit_time --审核时间
  36. ,'0' as is_audit
  37. ,'14' as actvt_class
  38. ,'0' as actvt_priority
  39. ,'0' as is_remind
  40. ,'0' as remind_ahead
  41. ,'0' as is_private
  42. ,'0' as is_repeat
  43. ,'0.00000000' as actual_cost
  44. ,'3' as actvt_status
  45. ,'' as event_location
  46. ,'1' as task_type
  47. ,'' as audit_opinion
  48. ,'' as strVouchID
  49. ,'0.00000000' as ne_approved_amount
  50. ,'' as event_address
  51. ,'0.00000000' as duration
  52. from SO_SOMain as a --销售订单主表
  53. where a.dcreatesystime >= dateadd(day,-2,getdate())
  54.   and a.csocode not in (select right(actvt_subject,len(actvt_subject)-7) as csocode
  55.                         from tc_activity where actvt_subject like '%新建销售订单:%')  --销售订单已经建立过行动日志的,不再建立
  56.  
  57. -------- select * from tc_activity
  58.  
  59. -------- select actvt_id,account_id,actvt_subject,actvt_multi01 from tc_activity where actvt_subject like '%新建销售订单:%'
  60.  
  61. -------- delete  from tc_activity where actvt_subject like '%新建销售订单:%'
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement