this is referring to my previous post: Link
System: Sql Server 2012
With this script I take the Friday values if the day of CutoffDate is Saturday or Sunday.
SELECT DISTINCT dbo.ECB.Currency + '-' + CAST(dbo.myTable.CutoffDate AS varchar(30)) AS ComboCurrDate, dbo.ECB.Rate AS ECBrate
FROM dbo.ECB INNER JOIN
dbo.myTable ON dbo.ECB.Date = CASE WHEN datepart(weekday, dbo.myTable.CutoffDate) IN (6, 7) THEN dateadd(d, - ((datepart(weekday,
dbo.myTable.CutoffDate) + 1 + @@DATEFIRST) % 7), dbo.myTable.CutoffDate) ELSE dbo.myTable.CutoffDate END AND
dbo.ECB.Currency = dbo.myTable.InvoiceCurrency
WHERE (dbo.myTable.InvoiceCurrency NOT LIKE 'EUR%')
But now I need to rewrite this to also deal with holidays. Or better, deal with non-existing records in the ECB-table.
For example: For Friday 29th March there is no record in the ECB-table but the myTable.CutoffDate is set to this date. With the above script I don't get values for this day.
How could I now assign the ECB-value of the 28th to the CutoffDate?
In general: If there is no record for a day in the ECB-table then try the previous date within the ECB-table and so on.
Hope I could explain this clearly.
Thank you for your help.