CREATE TABLE #AvailableDate (
CustomKey INT IDENTITY (1,1),
SelectedFaceID INT,
FromDate DATETIME,
ToDate DATETIME,
TempDate DATETIME,
Diff INT)
INSERT INTO #AvailableDate(SelectedFaceID, FromDate, ToDate, TempDate, Diff)
SELECT
SelectedFaceID,
FromDate,
ToDate,
(SELECT TOP 1 ToDate FROM #AvailableDate WITH(NOLOCK) ORDER BY #AvailableDate.CustomKey DESC),
(SELECT DATEDIFF(
d,
ToDate,
(SELECT TOP 1 ToDate FROM #AvailableDate ORDER BY CustomKey DESC)
)
)
FROM
SelectedFace WITH(NOLOCK)
ここではSELECT TOP 1 ToDate FROM #AvailableDate WITH(NOLOCK) ORDER BY #AvailableDate.CustomKey DESC
、上記のクエリの値またはに関連付けられた値を取得していません#AvailableDate