Ô´úÂ룺 /*¸£½¨¹«°²¸ßµÈר¿ÆÑ§Ð£µ±ÔÂÎÞ²¹ÖúÓÐǰÆÚ²¹ÖúµÄ¿¨ÊµÏÖÔÚ´°»úÉÏÁìÈ¡T-SQL´úÂ루µ±Ô²¹ÖúÐγɺ󷢷Åǰ´¦ÀíµÄ£©*/ declare @month/*Ô·Ý*/ datetime,@k /*¿¨Àà±ð*/ int,@customerid int /*¿Í»§ºÅ*/, @subsidyfare/*²¹Öú¶î*/ money select top 1 @month= month from t_subsidymonth order by month desc/*»ñÈ¡²¹Öúµ±Ô·ÝÖµ*/ declare k cursor for select cardtype from t_subsidymonth where plancount=0 and month=@month open k fetch next from k into @k while (@@fetch_status=0) begin declare custid_dist cursor for select distinct customerid from t_subsidynotputout where cardtype=@k open custid_dist fetch next from custid_dist into @customerid while (@@fetch_status=0) begin insert into t_subsidymonthplan(month,customerid,cardtype,subsidy) values(@month,@customerid,@k,0) –¹Ø¼ü fetch next from custid_dist into @customerid end close custid_dist deallocate custid_dist declare custid_subsidyfare cursor for select customerid,sum(subsidy) as sum_subsidy from t_subsidynotputout where cardtype=@k group by customerid open custid_subsidyfare fetch next from custid_subsidyfare into @customerid,@subsidyfare while (@@fetch_status=0) begin update t_customers set subsidydt=@month ,cursubsidyfare=@subsidyfare,subsidyout='F' where customerid =@customerid –¹Ø¼ü fetch next from custid_subsidyfare into @customerid,@subsidyfare end close custid_subsidyfare deallocate custid_subsidyfare fetch next from k into @k end close k deallocate k
ÓÅ»¯ºó´úÂ룺
declare @month/*Ô·Ý*/ datetime
select top 1 @month= month from t_subsidymonth order by month desc/*»ñÈ¡²¹Öúµ±Ô·ÝÖµ*/
update t_customers set t_customers.subsidydt=@month ,t_customers.cursubsidyfare=l.sum_subsidy ,t_customers.subsidyout='F' from ( select customerid,sum(subsidy) as sum_subsidy from t_subsidynotputout where cardtype in (select cardtype from t_subsidymonth where plancount=0 and month=@month) group by customerid) as l where t_customers.customerid=l.customerid
insert into t_subsidymonthplan(month,customerid,cardtype,subsidy) select subsidydt,customerid,cardtype,0 as subsidyfare from t_customers where customerid in (select distinct customerid from t_subsidynotputout where cardtype in (select cardtype from t_subsidymonth where plancount=0 and month=@month))
¸½£ºÓõ½µÄ»ù±¾±íÐÅÏ¢ ±íÃû£ºT_Customers£¨¿Í»§ÐÅÏ¢£© | ×Ö¶ÎÃû | ÀàÐÍ | ÒâÒå | ÊÇ·ñÖ÷¼ü | [CustomerID] | [int] NOT NULL | ¿Í»§´úÂë | Y | [StatCode] | [varchar] (3) NOT NULL | ¹¤×÷Õ¾´úÂë | | [Account] | [varchar] (7) NOT NULL | µ¥Î»´úÂë | | [Name] | [varchar] (12) NOT NULL | ÐÕÃû | | [CardNo] | [int] NOT NULL | ¿¨ºÅ | | [CardType] | [tinyint] NOT NULL | ¿¨Àà±ð | | [Status] | [tinyint] NOT NULL | ״̬ | | [OpenDt] | [datetime] NOT NULL | ²Ù×÷ÈÕÆÚ | | [CashID] | [smallint] NOT NULL | ³öÄÉÔ±´úÂë | | [SumFare] | [smallmoney] NOT NULL | ×ܶî | | [ConsumeFare] | [smallmoney] NOT NULL | Ïû·Ñ¶î | | [OddFare] | [smallmoney] NOT NULL | Óà¶î | | [OpCount] | [int] NOT NULL | ²Ù×÷´ÎÊý | | [CurSubsidyFare] | [smallmoney] NOT NULL | ±¾Ô²¹Öú·Ñ | * | [SubsidyDT] | [datetime] NOT NULL | ²¹ÖúÈÕÆÚ | * | [SubsidyOut] | [char] (1) NOT NULL | ·¢·Å±ê¼Ç | * | [Alias] | [varchar] (10) NULL | ±ðÃû | | [outid] | [varchar] (16) NULL | ¹¤ºÅ | | [UpdateID] | [tinyint] NOT NULL | ÊÇ·ñ¸üбê¼Ç | | [Pwd] | [char] (4) NULL | ÃÜÂë | | [QuChargFare] | [smallmoney] NULL | ÉêÇëתÕʽð¶î | | [HasTaken] | [tinyint] NULL | ÊÇ·ñÁìÈ¡ | | [DragonCardNo] | [char] (19) NULL | Áú¿¨¿¨ºÅ | | [ApplyCharg] | [smallmoney] NULL | Áì¿î½ð¶î | | [ChargPer] | [smallmoney] NULL | תÕʱê×¼ | | [MingZu] | [varchar] (20) NULL | Ãñ×å | | [Sex] | [char] (2) NULL | ÐÔ±ð | | [Memo] | [varchar] (100) NULL | ±¸×¢ | | [WeiPeiDW] | [varchar] (10) NULL | ίÅ൥λ | | [CardConsumeType] | [tinyint] NULL | ¿¨Ïû·ÑÀàÐÍ | | [LeaveSchoolDT] | [datetime] NULL | ÀëУÈÕÆÚ | |
±íÃû£ºT_SubsidyMonth£¨²¹ÖúÔºϼƣ© | ×Ö¶ÎÃû | ÀàÐÍ | ÒâÒå | ÊÇ·ñÖ÷¼ü | [Month] | [datetime] NOT NULL , | ²¹ÖúÔ | Y | [CardType] | [tinyint] NOT NULL , | ¿¨ÀàÐÍ | Y | [PlanCount] | [int] NOT NULL , | ¼Æ»®·¢·Å´ÎÊý | N | [PlanSubsidy] | [money] NOT NULL , | ¼Æ»®²¹Öú×ܶî | N | [PutOutCount] | [int] NOT NULL , | ÒÑ·¢²¹Öú´ÎÊý | N | [PutOutSubsidy] | [money] NOT NULL , | ÒÑ·¢²¹Öú½ð¶î | N | [LastCount] | [int] NOT NULL , | Ê£Óà´ÎÊý | N | [LastSubsidy] | [money] NOT NULL | Ê£ÓಹÖú | N | [PlanPre] | [money] NOT NULL | ǰÆÚδ·¢ | N | [PlanPreCount] | [int] NOT NULL , | ǰÆÚδ·¢´ÎÊý | N | [PutOutPre] | [money] NOT NULL , | ǰÆÚÒÑ·¢½ð¶î | N | [PutOutPreCount] | [int] NOT NULL , | ǰÆÚÒÑ·¢´ÎÊý | N | [LastPre] | [money] NOT NULL , | ǰÆÚÊ£Óà½ð¶î | N | [LastPreCount] |
|
|