视图创建.sql 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. --创建视图
  2. --按订单查询
  3. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderCustomerList]'))
  4. DROP VIEW [dbo].[Vw_OrderCustomerList]
  5. GO
  6. CREATE VIEW [Vw_OrderCustomerList]
  7. AS
  8. with t as(
  9. SELECT Plu_OrdNumber
  10. ,sum(Plu_Amount)as Plu_Amount
  11. FROM [dbo].[tb_ErpPlusPickItems]
  12. group by Plu_OrdNumber
  13. )
  14. , t2 as(
  15. SELECT [dbo].[tb_ErpOrder].[ID]
  16. ,[Ord_Number]
  17. ,[Ord_DividedShop]
  18. ,[Ord_Type]
  19. ,dbo.fn_CheckOrderType([Ord_Type]) as Ord_Type_CH
  20. ,[Ord_Class]
  21. ,[Ord_OrderClass]
  22. ,[Ord_PhotographyCategory]
  23. ,[Ord_CustomerSource]
  24. ,[Ord_SeriesName]
  25. ,[Ord_SeriesPrice]
  26. ,[Ord_CreateDateTime]
  27. ,[Ord_CreateName]
  28. ,[Ord_UpdateDateTime]
  29. ,[Ord_UpdateName]
  30. ,t.Plu_Amount
  31. FROM [dbo].[tb_ErpOrder]
  32. left join
  33. t
  34. on [tb_ErpOrder].[Ord_Number]=t.Plu_OrdNumber
  35. )
  36. select t2.*
  37. ,(isnull(t2.Plu_Amount,0)+isnull(t2.Ord_SeriesPrice,0))as yingFuPrice
  38. ,[GP_CustomerGroupID]
  39. ,[GP_GroupType]
  40. ,[GP_CustomerType]
  41. ,[GP_CustomerStatus]
  42. ,[GP_LossReason]
  43. ,[GP_DegreeOfIntent]
  44. ,[GP_CustomerSource]
  45. ,[GP_IntroducerCustomerID]
  46. ,[GM_CustomerGroupID]
  47. ,[Cus_Name]
  48. ,[Cus_Name_py]
  49. ,[Cus_Sex_cs]
  50. ,[Cus_Telephone]
  51. ,[Cus_Region]
  52. ,[Age_String]
  53. ,[Age_Day]
  54. ,[Age_Year]
  55. ,[GregorianCalendar_Birthday]
  56. ,[GregorianCalendar_NowYearBirthday]
  57. ,[GregorianCalendar_DayForMarriage]
  58. ,[GregorianCalendar_NowYearDayForMarriage]
  59. ,[M_Cus_CustomerNumber]
  60. ,[M_Cus_Name]
  61. ,[M_Cus_Name_py]
  62. ,[M_Cus_Sex_cs]
  63. ,[M_Cus_Telephone]
  64. ,[M_Cus_MicroSignal]
  65. ,[M_Cus_QQ]
  66. ,[M_Cus_Region]
  67. ,[M_Cus_Address]
  68. ,[Ord_ViceOrderCount]
  69. ,[Mc_CradNumber]
  70. ,[Mc_CardType]
  71. from t2
  72. left join
  73. [dbo].[tempTB_AggregationCustomer]
  74. on t2.[Ord_Number]=dbo.[tempTB_AggregationCustomer].[GP_OrderNumber]
  75. GO
  76. --按人查询
  77. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_PersonalCustomerList]'))
  78. DROP VIEW [dbo].[Vw_PersonalCustomerList]
  79. GO
  80. CREATE VIEW [Vw_PersonalCustomerList]
  81. AS
  82. with t as(
  83. SELECT Plu_OrdNumber
  84. ,sum(Plu_Amount)as Plu_Amount
  85. FROM [dbo].[tb_ErpPlusPickItems]
  86. group by Plu_OrdNumber
  87. )
  88. , t2 as(
  89. SELECT [dbo].[tb_ErpOrder].[ID]
  90. ,[Ord_Number]
  91. ,[Ord_DividedShop]
  92. ,[Ord_Type]
  93. ,dbo.fn_CheckOrderType([Ord_Type]) as Ord_Type_CH
  94. ,[Ord_Class]
  95. ,[Ord_OrderClass]
  96. ,[Ord_PhotographyCategory]
  97. ,[Ord_CustomerSource]
  98. ,[Ord_SeriesName]
  99. ,[Ord_SeriesPrice]
  100. ,[Ord_CreateDateTime]
  101. ,[Ord_CreateName]
  102. ,[Ord_UpdateDateTime]
  103. ,[Ord_UpdateName]
  104. ,t.Plu_Amount
  105. FROM [dbo].[tb_ErpOrder]
  106. left join
  107. t
  108. on [tb_ErpOrder].[Ord_Number]=t.Plu_OrdNumber
  109. )
  110. select t2.*
  111. ,(isnull(t2.Plu_Amount,0)+isnull(t2.Ord_SeriesPrice,0))as yingFuPrice
  112. ,[GP_CustomerGroupID]
  113. ,[GP_GroupType]
  114. ,[GP_CustomerType]
  115. ,[GP_CustomerStatus]
  116. ,[GP_LossReason]
  117. ,[GP_DegreeOfIntent]
  118. ,[GP_CustomerSource]
  119. ,[GP_IntroducerCustomerID]
  120. ,[GP_Remark]
  121. ,[GP_BelongsPersonID]
  122. ,[GP_CreateDatetime]
  123. ,[GP_UpdateDatetime]
  124. ,[GM_CustomerGroupID]
  125. ,[GM_CustomerID]
  126. ,[GM_Master]
  127. ,[GM_ProtagonistCustomer]
  128. ,[GM_RelatedPersonID]
  129. ,[GM_Relation]
  130. ,[GM_IsOrder]
  131. ,[GM_IsOrderNumber]
  132. ,[Cus_CustomerNumber]
  133. ,[Cus_CustomizeNumber]
  134. ,[Cus_Grade]
  135. ,[Cus_Name]
  136. ,[Cus_Name_py]
  137. ,[Cus_Sex]
  138. ,[Cus_Sex_cs]
  139. ,[Cus_Birthday]
  140. ,[Cus_BirthdayLunar]
  141. ,[GregorianCalendar_Birthday]
  142. ,[GregorianCalendar_NowYearBirthday]
  143. ,[Age_Year]
  144. ,[Age_Day]
  145. ,[Age_String]
  146. ,[Cus_DayForMarriage]
  147. ,[Cus_DayForMarriageLunar]
  148. ,[GregorianCalendar_DayForMarriage]
  149. ,[GregorianCalendar_NowYearDayForMarriage]
  150. ,[Cus_QQ]
  151. ,[Cus_MicroSignal]
  152. ,[Cus_Telephone]
  153. ,[Cus_FixedPhone]
  154. ,[Cus_Region]
  155. ,[Cus_Address]
  156. ,[Cus_WorkUnit]
  157. ,[Cus_BabyWeight]
  158. ,[Cus_BornHospital]
  159. ,[Cus_Zodiac]
  160. ,[Cus_CustomerSource]
  161. ,[Cus_Status]
  162. ,[Cus_DegreeOfIntent]
  163. ,[Cus_TrackName]
  164. ,[Cus_CreateDateTime]
  165. ,[Cus_CreateName]
  166. ,[Cus_UpdateDateTime]
  167. ,[Cus_UpdateName]
  168. from t2
  169. left join
  170. dbo.View_CustomerGroupAndCustomerGroupMembersAndErpCustomer
  171. on t2.[Ord_Number]=dbo.View_CustomerGroupAndCustomerGroupMembersAndErpCustomer.[GP_OrderNumber]
  172. GO
  173. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_MemorialDayEmployeeList]'))
  174. DROP VIEW [dbo].[Vw_MemorialDayEmployeeList]
  175. GO
  176. CREATE VIEW [Vw_MemorialDayEmployeeList]
  177. AS
  178. SELECT [ID]
  179. ,[User_Name]
  180. ,[User_Sex]
  181. ,[User_Telephone]
  182. ,User_DateOfBirth
  183. ,dbo.Fun_GetGregorianCalendarNowYearBirthday([User_DateOfBirth],[User_BirthdayLunar]) as GregorianCalendar_NowYearBirthday
  184. FROM [dbo].[tb_ErpUser]
  185. where User_Status='在职'
  186. and len(User_DateOfBirth)>=10
  187. and len(User_DateOfBirth)>=10
  188. and len(User_Telephone)>=11
  189. GO