select NFast_No from Web_FTT_Param where getdate() between Begin_date and End_date select top 100 cancel_month, dateadd(day, -day(cancel_month), cancel_month) as lastmonth from tbl_customer_cancellation update tbl_customer_cancellation set lastactivemonth = dateadd(day, -day(cancel_month), cancel_month) --增減月份時,統一以每月1日為基準,避免注意大小月份日期不一,增減以後造成錯誤。 update tbl_customer_cancellation set First4Month = dateadd(day, -1, dateadd(month, 3, dateadd(day, -day(pc_date)+1, pc_date))) ,Last4Month = dateadd(day, -1, dateadd(month, -3, dateadd(day, -day(cancel_month)+1, cancel_month))) select top 100 cancel_month ,dateadd(day, -1, dateadd(month, -3, dateadd(day, -day(cancel_month)+1, cancel_month))) ,pc_date ,dateadd(day, -1, dateadd(month, 3, dateadd(day, -day(pc_date)+1, pc_date))) from tbl_customer_cancellation select top 100 pc_date, first3month, last4month, lastactivemonth from tbl_customer_cancellation