4,707 questions
Maybe this:
INSERT INTO #TempPreviousModel(ID,ModelFile,DownloadDate,Ticker,Client)
SELECT isnull(MI.ID, 0), isnull(MI.ModelFile, 'NOTFOUND-' + cm.ModelName),
isnull(MI.DownloadDate, sysdatetime()), isnull(MI.Ticker, cm.Ticker),
isnull(MI.Client, cm.Client)
FROM #tempCurrentModel CM
OUTER APPLY (SELECT TOP 1 M.ID, MI.ModelFile, MI.DownloadDate, MI.Ticker,Client
FROM tblOriginalModelInput MI
WHERE convert(date, MI.downloaddate) < convert(date ,GetDate())
AND MI.ModelFile LIKE cm.ModelName+'%'
AND MI.Ticker IN (select T.Ticker from tblTicker T WHERE Active='A' AND Published='Y')
ORDER BY MI.downloaddate DESC) AS MI
Note that since you did not provide table definitions or test data, I have not been able to test this.
By the way, I took the liberty to change this condition:
WHERE Convert(varchar(10),downloaddate,112) < convert(varchar(10),GetDate(),121)
As looks very funny. Format 112 is YYYYMMDD, while 121 is YYYY-MM-DD, so that comparison could yield unexpected results.