日期:2014-05-18 浏览次数:21014 次
INSERT INTO StatusData.dbo.DataMissingReport ( InvestmentId, InvestmentType, ReportTypeId, EffectiveDate, UserId, Status, Action, ExpectedTime, LastUpdate ,FrequencyPattern, MarketHolidayId ) SELECT pfi.InvestmentId AS InvestmentId, pfi.InvestmentType AS InvestmentType, dm.ReportTypeId, @l_EffectiveDate AS EffectiveDate, -1 AS UserId, 1 AS Status, 0 AS Action, CASE WHEN pfi.DelayInDays = 0 THEN @r_WorkingDay1 WHEN pfi.DelayInDays = 1 THEN @r_WorkingDay2 WHEN pfi.DelayInDays = 2 THEN @r_WorkingDay3 WHEN pfi.DelayInDays = 3 THEN @r_WorkingDay4 WHEN pfi.DelayInDays = 4 THEN @r_WorkingDay5 WHEN pfi.DelayInDays = 5 THEN @r_WorkingDay6 WHEN pfi.DelayInDays = 6 THEN @r_WorkingDay7 WHEN pfi.DelayInDays = 7 THEN @r_WorkingDay8 WHEN pfi.DelayInDays = 8 THEN @r_WorkingDay9 WHEN pfi.DelayInDays = 9 THEN @r_WorkingDay10 ELSE DATEADD( DAY ,pfi.DelayInDays -10 +((@l_WorkdayNoOfWorkingDay10 + pfi.DelayInDays -10)/5)*2, @r_WorkingDay10 ) END AS ExpectedTime, @l_CurrentTime AS LastUpdate, @l_FrequencyPattern AS FrequencyPattern, phm.MarketHolidayId AS MarketHolidayId FROM SupportData.dbo.PerformanceFeedInfoHistory pfi WITH (NOLOCK) INNER JOIN BasicData.dbo.InvestmentStaticInfo idr WITH (NOLOCK) ON pfi.InvestmentId = idr.GeneralId --AND pfi.InvestmentType = idr.PerformanceType INNER JOIN StatusData.dbo.DataPointReportTypeIdMapping dm WITH (NOLOCK) ON dm.DataPointType = pfi.DataPointType INNER JOIN BasicData.dbo.DataUnitUniverseSetting dus WITH (NOLOCK) ON dus.DataUnitId = dm.DataUnitId AND idr.Universe = dus.Universe INNER JOIN BasicData.dbo.DataUnitDomicileSetting dds WITH (NOLOCK) ON dds.DataUnitId = dm.DataUnitId AND ( dds.Domicile = '*' OR dds.Domicile = idr.CountryId ) INNER JOIN BasicData.dbo.PerformanceMarketHolidayMapping phm WITH (NOLOCK) ON phm.PerformanceId = idr.PerformanceId INNER JOIN dbo.fn_SplitStringToTable ( @l_MarketHolidayIds,',' ) a ON a.Value = phm.MarketHolidayId WHERE pfi.FrequencyPattern = @l_FrequencyPattern --AND idr.DataReadiness = 1 --AND pfi.DataPointType<>23 AND pfi.MarkLatest = 1 AND dm.ReportCategory = 1 AND NOT EXISTS ( SELECT 1 FROM StatusData.dbo.DataMissingReport dt WITH (NOLOCK) WHERE dt.InvestmentId = idr.PerformanceId10Char AND dt.InvestmentType = idr.PerformanceType AND dt.ReportTypeId = dm.ReportTypeId AND dt.EffectiveDate = @p_EffectiveDate)