员工表新增字段.sql 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. -- 员工个人电话;
  2. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_self_phone')
  3. ALTER table [renyuan] ADD [staff_self_phone] [varchar](11) NOT NULL
  4. -- 员工父亲姓名;
  5. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_father')
  6. ALTER table [renyuan] ADD [staff_father] [nvarchar](12) NOT NULL
  7. -- 员工母亲姓名;
  8. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_mother')
  9. ALTER table [renyuan] ADD [staff_mother] [nvarchar](12) NOT NULL
  10. -- 员工父亲电话;
  11. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_father_phone')
  12. ALTER table [renyuan] ADD [staff_father_phone] [varchar](11) NOT NULL
  13. -- 员工母亲电话;
  14. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_mother_phone')
  15. ALTER table [renyuan] ADD [staff_mother_phone] [varchar](11) NOT NULL
  16. -- 紧急联系人姓名;
  17. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_emergency_name')
  18. ALTER table [renyuan] ADD [staff_emergency_name] [nvarchar](12) NOT NULL
  19. -- 紧急联系人电话;
  20. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_emergency_phone')
  21. ALTER table [renyuan] ADD [staff_emergency_phone] [varchar](11) NOT NULL
  22. -- 紧急联系人关系;
  23. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_emergency_relationship')
  24. ALTER table [renyuan] ADD [staff_emergency_relationship] [nvarchar](8) NOT NULL
  25. -- 家庭住址;
  26. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_family_address')
  27. ALTER table [renyuan] ADD [staff_family_address] [nvarchar](8) NOT NULL
  28. -- 入职时间;
  29. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_hire_date')
  30. ALTER table [renyuan] ADD [staff_hire_date] [datetime] NOT NULL
  31. -- 离职时间;
  32. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_leave_date')
  33. ALTER table [renyuan] ADD [staff_leave_date] [datetime] NOT NULL
  34. -- 个人QQ;
  35. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_self_qq')
  36. ALTER table [renyuan] ADD [staff_self_qq] [nvarchar](8) NOT NULL
  37. -- 个人微信;
  38. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_self_weixin')
  39. ALTER table [renyuan] ADD [staff_self_weixin] [nvarchar](8) NOT NULL
  40. -- 个人email;
  41. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_self_email')
  42. ALTER table [renyuan] ADD [staff_self_email] [nvarchar](8) NOT NULL
  43. -- 学历;
  44. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_educational')
  45. ALTER table [renyuan] ADD [staff_educational] [nvarchar](8) NOT NULL
  46. -- 学历;
  47. IF NOT EXISTS(select name FROM syscolumns WHERE id=object_id('renyuan') AND name='staff_educational')
  48. ALTER table [renyuan] ADD [staff_educational] [nvarchar](8) NOT NULL
  49. ------------------------------------------------------------------------------------------------------
  50. --dindanbukuan2表 新添加字段;
  51. --对接人;pick up man;
  52. if not exists(select name from syscolumns where id=object_id('dindanbukuan2') and name='pick_up_man')
  53. alter table [dindanbukuan2] add [pick_up_man] [nvarchar](12) NULL
  54. --对接人部门;
  55. if not exists(select name from syscolumns where id=object_id('dindanbukuan2') and name='pick_up_dept')
  56. alter table [dindanbukuan2] add [pick_up_dept] [nvarchar](12) NULL
  57. --实收款;amount received
  58. if not exists(select name from syscolumns where id=object_id('dindanbukuan2') and name='amount_received')
  59. alter table [dindanbukuan2] add [amount_received] [nvarchar](12) NULL
  60. --接单人;Order Taker
  61. if not exists(select name from syscolumns where id=object_id('dindanbukuan2') and name='order_taker')
  62. alter table [dindanbukuan2] add [order_taker] [nvarchar](12) NULL
  63. if not exists(select name from syscolumns where id=object_id('dindanbukuan2') and name='order_taker_dept')
  64. alter table [dindanbukuan2] add [order_taker_dept] [nvarchar](12) NULL
  65. --服务状态;service state
  66. if not exists(select name from syscolumns where id = object_id('dindanbukuan2') and name = 'service_state')
  67. alter table [dindanbukuan2] add [service_state] [nvarchar] (8) null
  68. ------------------------------------------------------------------------------------------------------
  69. --dindan表 同样添加相应字段;
  70. --对接人;pick up man;
  71. if not exists(select name from syscolumns where id=object_id('dindan') and name='pick_up_man')
  72. alter table [dindan] add [pick_up_man] [nvarchar](12) NULL
  73. --对接人部门;
  74. if not exists(select name from syscolumns where id=object_id('dindan') and name='pick_up_dept')
  75. alter table [dindan] add [pick_up_dept] [nvarchar](12) NULL
  76. --实收款;amount received
  77. if not exists(select name from syscolumns where id=object_id('dindan') and name='amount_received')
  78. alter table [dindan] add [amount_received] [nvarchar](12) NULL
  79. --接单人;Order Taker
  80. if not exists(select name from syscolumns where id=object_id('dindan') and name='order_taker')
  81. alter table [dindan] add [order_taker] [nvarchar](12) NULL
  82. --服务状态;service state
  83. if not exists(select name from syscolumns where id = object_id('dindan') and name = 'service_state')
  84. alter table [dindan] add [service_state] [nvarchar] (8) null
  85. -------------------------------------------------------------------------------------------------------
  86. --服务状态;service state
  87. if not exists(select name from syscolumns where id = object_id('workerreport') and name = 'staff_dept')
  88. alter table [workerreport] add [staff_dept] [nvarchar] (12) null
  89. -------------------------------------------------------------------------------------------------------
  90. -- 生成加挑项目视图;
  91. DROP VIEW [dbo].[receipt_item]
  92. CREATE VIEW receipt_item as
  93. select
  94. dindanbukuan2.autoid, --自增列;
  95. dindan.id , --订单号;
  96. dindan.name1 , --老板;
  97. dindan.name2 , --影楼;
  98. dindan.phone1 , --老板电话;
  99. dindanbukuan2.bz , --加挑项目;
  100. dindanbukuan2.money , --加挑金额(应收款);
  101. dindanbukuan2.order_taker , --开单人;
  102. dindanbukuan2.order_taker_dept , --开单人部门;
  103. dindanbukuan2.amount_received , --实收款;
  104. dindanbukuan2.pick_up_man , --对接人;
  105. dindanbukuan2.pick_up_dept , --对接人部门;
  106. dindanbukuan2.service_state , --服务状态;
  107. dindanbukuan2.ren2 , --录单人;
  108. dindanbukuan2.date --录单时间;
  109. from dindan inner join dbo.dindanbukuan2 ON dbo.dindan.id = dbo.dindanbukuan2.id
  110. GO
  111. -- 更新订单实收款, 从已收的收款记录中提取;
  112. ;with tt as(
  113. select sum(cast ([money] as bigint)) as summoney,id from dindanbukuan where kind = '3' or kind = '4' group by id
  114. ) update dindan set dindan.amount_received = cast((select summoney from tt where dindan.id = tt.id) as nvarchar)
  115. -- 更新订单加挑实收款,从已收的收款中提取;
  116. ;with tt as(
  117. select sum(cast ([money] as bigint)) as summoney,id,item as receipt_item from dindanbukuan where kind <> '3' and kind <> '4' group by id,item --order by id
  118. ) update dindanbukuan2 set amount_received = cast((select summoney from tt where dindanbukuan2.id = tt.id and dindanbukuan2.bz=tt.receipt_item) as nvarchar)