我一直在寻找将表插入成本从75%降低到最低的方法。我认为我们要在插入之前创建临时表的一种方法,但这没有帮助,还有其他方法可以改善对临时表的插入。
@StartDate date = null,
@EndDate date = null
IF @StartDate IS NULL AND @EndDate IS NULL
BEGIN
SET @StartDate = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + -12, 0)
SET @EndDate = DATEADD(MILLISECOND, -3, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0))
END
SELECT CustomerId, LogDate, StartDate = @StartDate, EndDate = @EndDate
INTO #Temp1
FROM Log l
where l.LogDate >= @StartDate and l.LogDate < dateadd(day, 1, @EndDate)
select
l.*,
a.StateId,
a.CountryId
into #Temp
from #Temp1 l
JOIN [Address] a ON a.CustomerId = l.CustomerId