I want to take the value of ExtractedDate from this query and use it as @LastExtractDate in the next query. How do I do that?
SELECT TOP 1 [ExtractedDate]
FROM [OnsiteV4].[dbo].[SqlPendingIndex] order by ExtractedDate desc
next query:
insert into @table(Hex, KeyDeviceId, ObjectDateTime, ExtractedDate )
SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), ObjectValue, 1)) AS Hex, KeyDeviceId, ObjectDateTime , GETDATE ()
FROM SQLPending
WHERE (ObjectSubType LIKE '%GAS%') and (ObjectDateTime > @LastExtractDate)