2
使用COALESCE(…)优化子查询的选择
我在应用程序中使用的视图很大。我认为我已经缩小了性能问题,但是不确定如何解决。视图的简化版本如下所示: SELECT ISNULL(SEId + '-' + PEId, '0-0') AS Id, *, DATEADD(minute, Duration, EventTime) AS EventEndTime FROM ( SELECT se.SEId, pe.PEId, COALESCE(pe.StaffName, se.StaffName) AS StaffName, -- << Problem! COALESCE(pe.EventTime, se.EventTime) AS EventTime, COALESCE(pe.EventType, se.EventType) AS EventType, COALESCE(pe.Duration, se.Duration) AS Duration, COALESCE(pe.Data, se.Data) AS Data, COALESCE(pe.Field, se.Field) AS Field, pe.ThisThing, se.OtherThing …