Forum Discussion
Convert Sales from local currency to Dollar with missing dates
- 3 years ago
hello, i ended up repopulating the exchange table with missing dates, with rate of missing dates taking the value of previous date. the exchange table looks like this now:
with tmp(plant_date) as
(
select cast('20210101' as datetime)
union all
select plant_date + 1
from tmp
where plant_date < '20301231'
)select 'US2' as [Currency Code],dt as [Starting Date],max([Relational Exch_ Rate Amount]) over (partition by grp) [Relational Exch_ Rate Amount]
from
(
select coalesce([Starting Date],plant_date) dt,[Relational Exch_ Rate Amount],
SUM(CASE WHEN [Relational Exch_ Rate Amount] IS NOT NULL THEN 1 ELSE 0 END) OVER(
ORDER BY plant_date
ROWS UNBOUNDED PRECEDING) grp
from tmp left join (select [Currency Code],[Starting Date],[Relational Exch_ Rate Amount]
from Till.dbo.[UCCM$Currency Exchange Rate] where [Currency Code]='US2')
#t on tmp.plant_date=#t.[Starting Date]
) as der
option (maxrecursion 0)
hello, i ended up repopulating the exchange table with missing dates, with rate of missing dates taking the value of previous date. the exchange table looks like this now:
with tmp(plant_date) as
(
select cast('20210101' as datetime)
union all
select plant_date + 1
from tmp
where plant_date < '20301231'
)
select 'US2' as [Currency Code],dt as [Starting Date],max([Relational Exch_ Rate Amount]) over (partition by grp) [Relational Exch_ Rate Amount]
from
(
select coalesce([Starting Date],plant_date) dt,[Relational Exch_ Rate Amount],
SUM(CASE WHEN [Relational Exch_ Rate Amount] IS NOT NULL THEN 1 ELSE 0 END) OVER(
ORDER BY plant_date
ROWS UNBOUNDED PRECEDING) grp
from tmp left join (select [Currency Code],[Starting Date],[Relational Exch_ Rate Amount]
from Till.dbo.[UCCM$Currency Exchange Rate] where [Currency Code]='US2')
#t on tmp.plant_date=#t.[Starting Date]
) as der
option (maxrecursion 0)