12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PROCE_UpdateAggregationCustomer]') AND type in (N'P', N'PC'))
- DROP PROCEDURE [dbo].[PROCE_UpdateAggregationCustomer]
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- CREATE PROCEDURE [dbo].[PROCE_UpdateAggregationCustomer]
- (
- @WhereString varchar(2000) =N'',
- @ReturnI int output
- )
- AS
- BEGIN
- DECLARE @M_Cus_CustomerNumber varchar(2000)
- DECLARE @GP_CustomerGroupID varchar(2000)
-
- delete [tempTB_AggregationCustomer] where len(@WhereString)>0 and (GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
- insert into [tempTB_AggregationCustomer]
- select * from [Vw_AggregationCustomer]
- where len(@WhereString)>0 and (GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
- set @ReturnI=(select count(*) from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
-
-
- set @M_Cus_CustomerNumber=(select top 1 M_Cus_CustomerNumber from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
- delete [tempTB_GroupByAggregationCustomer] where M_Cus_CustomerNumber =@M_Cus_CustomerNumber;
- set @GP_CustomerGroupID=(select top 1 GP_CustomerGroupID from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
- delete [tempTB_GroupByAggregationCustomer] where GP_CustomerGroupID =@GP_CustomerGroupID;
- with t as(
- SELECT
- max(GP_CustomerGroupID) as GP_CustomerGroupID
- from tempTB_AggregationCustomer
- where M_Cus_CustomerNumber =@M_Cus_CustomerNumber
- group by Cus_Name,M_Cus_CustomerNumber
- ),t2 as(
- select * from tempTB_AggregationCustomer
- where GP_CustomerGroupID in (select GP_CustomerGroupID from t)
- )
- insert into [tempTB_GroupByAggregationCustomer] select * from t2
-
- END
- GO
- IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PROCE_UpdateAggregationCustomerAll]') AND type in (N'P', N'PC'))
- DROP PROCEDURE [dbo].[PROCE_UpdateAggregationCustomerAll]
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- CREATE PROCEDURE [dbo].[PROCE_UpdateAggregationCustomerAll]
- (
- @ReturnI int output
- )
- AS
- BEGIN
- truncate table [dbo].[tempTB_AggregationCustomer]
- insert into [tempTB_AggregationCustomer] select * from [Vw_AggregationCustomer]
- truncate table [dbo].[tempTB_GroupByAggregationCustomer]
- insert into [tempTB_GroupByAggregationCustomer] select * from [Vw_GroupByAggregationCustomer]
- set @ReturnI=(select count(*) from [tempTB_AggregationCustomer])
-
- END
- GO
|