Select Top 1 field and assign to local variable
why not use this:
declare @LastExtractDate date
SELECT TOP 1 @LastExtractDate=[ExtractedDate]
FROM [OnsiteV4].[dbo].[SqlPendingIndex] order by ExtractedDate desc
Simply declare & assign:
DECLARE @LastExtractDate DATETIME = (
SELECT TOP 1 [ExtractedDate] FROM [OnsiteV4].[dbo].[SqlPendingIndex] order by ExtractedDate desc
)
or better:
DECLARE @LastExtractDate DATETIME = (
SELECT MAX(ExtractedDate) FROM [OnsiteV4].[dbo].[SqlPendingIndex]
)