123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_AggregationCustomer]'))
- DROP VIEW [dbo].[Vw_AggregationCustomer]
- GO
- CREATE VIEW [dbo].[Vw_AggregationCustomer]
- as
- with t as(
- select
- GM_CustomerGroupID
- ,CONVERT(varchar(200),dbo.FunTrim(dbo.AggregateString([Cus_Name]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')
- +'/'+ dbo.AggregateString([Cus_Name]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}<>{$$}本人{$$}s'),'/')) as Cus_Name
-
- ,CONVERT(varchar(200),dbo.FunTrim(dbo.AggregateString([Cus_Name_py]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')
- +'/'+ dbo.AggregateString([Cus_Name_py]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}<>{$$}本人{$$}s'),'/')) as Cus_Name_py
-
- ,CONVERT(varchar(200),dbo.FunTrim(dbo.AggregateString([Cus_Sex_cs]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')
- +'/'+ dbo.AggregateString([Cus_Sex_cs]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}<>{$$}本人{$$}s'),'/')) as Cus_Sex_cs
-
- ,CONVERT(varchar(200),dbo.FunTrim(dbo.AggregateString([Cus_Telephone]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')
- +'/'+ dbo.AggregateString([Cus_Telephone]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}<>{$$}本人{$$}s'),'/')) as Cus_Telephone
-
-
- ,CONVERT(varchar(200),dbo.FunTrim(dbo.AggregateString([Cus_Region]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')
- +'/'+ dbo.AggregateString([Cus_Region]+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}<>{$$}本人{$$}s'),'/')) as Cus_Region
-
- ,CONVERT(varchar(200),dbo.AggregateString(CONVERT(varchar(10),[Age_String])+'{$$}/{where}'+CONVERT(varchar(1),[GM_ProtagonistCustomer])+'{$$}={$$}1{$$}i')) as Age_String
- ,CONVERT(int,dbo.AggregateString(CONVERT(varchar(10),[Age_Day])+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')) as Age_Day
-
- ,CONVERT(int,dbo.AggregateString(CONVERT(varchar(10),[Age_Year])+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')) as Age_Year
-
- ,CONVERT(datetime,dbo.AggregateString(CONVERT(varchar(10),[GregorianCalendar_Birthday])+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')) as GregorianCalendar_Birthday
-
- ,CONVERT(datetime,dbo.AggregateString(CONVERT(varchar(10),[GregorianCalendar_NowYearBirthday])+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')) as GregorianCalendar_NowYearBirthday
-
- ,CONVERT(datetime,dbo.AggregateString(CONVERT(varchar(10),[GregorianCalendar_DayForMarriage])+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')) as GregorianCalendar_DayForMarriage
-
- ,CONVERT(datetime,dbo.AggregateString(CONVERT(varchar(10),[GregorianCalendar_NowYearDayForMarriage])+'{$$}/{where}'+CONVERT(varchar(5),[GM_Relation])+'{$$}={$$}本人{$$}s')) as GregorianCalendar_NowYearDayForMarriage
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_CustomerNumber]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_CustomerNumber
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_Name]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_Name
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_Name_py]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_Name_py
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_Sex_cs]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_Sex_cs
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_Telephone]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_Telephone
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_MicroSignal]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_MicroSignal
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_QQ]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_QQ
- ,CONVERT(varchar(200),dbo.AggregateString([Cus_Region]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i')) as M_Cus_Region
- ,dbo.AggregateString([Cus_Address]+'{$$}/{where}'+CONVERT(varchar(1),[GM_Master])+'{$$}={$$}1{$$}i') as M_Cus_Address
- ,count(Cus_CustomerNumber) as Ord_ViceOrderCount
- from
- dbo.View_CustomerGroupMembersAndErpCustomer
- group by GM_CustomerGroupID
- )
- select
- [tb_ErpCustomerGroup].id
- ,[GP_OrderNumber]
- ,[GP_CustomerGroupID]
- ,[GP_GroupType]
- ,[GP_CustomerType]
- ,[GP_CustomerStatus]
- ,[GP_LossReason]
- ,[GP_DegreeOfIntent]
- ,[GP_CustomerSource]
- ,GP_CreateDatetime
- ,GP_UpdateDatetime
- ,GP_ISIntentionCustomer
- ,GP_ReminderTime
- ,[GP_IntroducerCustomerID],t.*
- ,[dbo].[Vw_ErpMemberCardSimpleInfo].[Mc_CradNumber]
- ,[dbo].[Vw_ErpMemberCardSimpleInfo].[Mc_CardType]
- from
- [tb_ErpCustomerGroup]
- left join
- t
- on [tb_ErpCustomerGroup].[GP_CustomerGroupID]=t.[GM_CustomerGroupID]
- left join
- [dbo].[Vw_ErpMemberCardSimpleInfo]
- on t.M_Cus_CustomerNumber=[dbo].[Vw_ErpMemberCardSimpleInfo].[Mc_CustomerNumber]
- GO
- IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tempTB_AggregationCustomer]'))
- DROP table [dbo].[tempTB_AggregationCustomer]
- GO
- select * into tempTB_AggregationCustomer from [Vw_AggregationCustomer]
- go
- CREATE UNIQUE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_GP_CustomerGroupID] ON [dbo].[tempTB_AggregationCustomer]
- (
- [GP_CustomerGroupID] desc
- )
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_GP_OrderNumber] ON [dbo].[tempTB_AggregationCustomer]
- (
- [GP_OrderNumber] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_Cus_Name] ON [dbo].[tempTB_AggregationCustomer]
- (
- [Cus_Name] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_Cus_Name_py] ON [dbo].[tempTB_AggregationCustomer]
- (
- Cus_Name_py desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_Cus_Telephone] ON [dbo].[tempTB_AggregationCustomer]
- (
- Cus_Telephone desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_GP_CustomerSource] ON [dbo].[tempTB_AggregationCustomer]
- (
- [GP_CustomerSource] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_M_Cus_Name] ON [dbo].[tempTB_AggregationCustomer]
- (
- [M_Cus_Name] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_M_Cus_Name_py] ON [dbo].[tempTB_AggregationCustomer]
- (
- M_Cus_Name_py desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_M_Cus_Telephone] ON [dbo].[tempTB_AggregationCustomer]
- (
- M_Cus_Telephone desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_AggregationCustomer_Mc_CradNumber] ON [dbo].[tempTB_AggregationCustomer]
- (
- Mc_CradNumber desc
- )
- go
- IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_GroupByAggregationCustomer]'))
- DROP VIEW [dbo].[Vw_GroupByAggregationCustomer]
- GO
- CREATE VIEW [Vw_GroupByAggregationCustomer]
- AS
- with t as(
- SELECT
- max(GP_CustomerGroupID) as GP_CustomerGroupID
- from tempTB_AggregationCustomer
- group by Cus_Name,M_Cus_CustomerNumber
- )
- select * from tempTB_AggregationCustomer
- where GP_CustomerGroupID in (select GP_CustomerGroupID from t)
- go
- IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tempTB_GroupByAggregationCustomer]'))
- DROP table [dbo].[tempTB_GroupByAggregationCustomer]
- GO
- select * into tempTB_GroupByAggregationCustomer from [Vw_GroupByAggregationCustomer]
- go
- CREATE UNIQUE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_GP_CustomerGroupID] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- [GP_CustomerGroupID] desc
- )
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_GP_OrderNumber] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- [GP_OrderNumber] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_Cus_Name] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- [Cus_Name] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_Cus_Name_py] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- Cus_Name_py desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_Cus_Telephone] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- Cus_Telephone desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_GP_CustomerSource] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- [GP_CustomerSource] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_M_Cus_Name] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- [M_Cus_Name] desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_M_Cus_Name_py] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- M_Cus_Name_py desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_M_Cus_Telephone] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- M_Cus_Telephone desc
- )
- go
- CREATE NONCLUSTERED INDEX [IX_tempTB_GroupByAggregationCustomer_Mc_CradNumber] ON [dbo].[tempTB_GroupByAggregationCustomer]
- (
- Mc_CradNumber desc
- )
- go
|