Script to update historical exchange rate
This script will update the exchange rate on orders which have already been created.
Orders in the database have an exchange rate column. To calculate and show sales data for orders connected to campaigns and discounts, the system uses data from ExchangeRate and BaseCurrencyCode columns.
Not all orders in Litium 7, and Litium 8 have base currencies and exchange rates. This script will fill in that data, and update the exchange rate value on historical orders.
Updating the exchange rates on already placed orders may provide improved statistical reports.
--Finds and updates historical Orders that are missing BaseCurrencyCode and ExchangeRate.
--Defines the Base currency code to set for historical Orders
DECLARE @baseCurrencyCode nvarchar(5) = 'SEK'
--Defines the Currency code which Orders were paid with
DECLARE @currencyCode nvarchar(5) = 'USD'
--Defines the exchange rate, to convert from @currencyCode to @baseCurrencyCode
DECLARE @exchangeRate decimal(18,8) = 9.87
--Defines from date, to get orders in the specific date range
DECLARE @fromDate datetimeoffset(7) = '2022/04/25'
--Defines to date, to get orders in the specific date range
DECLARE @toDate datetimeoffset(7) = '2022/05/27'
UPDATE [Sales].[Order]
SET BaseCurrencyCode = @baseCurrencyCode, ExchangeRate = @exchangeRate
WHERE BaseCurrencyCode IS NULL AND CurrencyCode = @currencyCode AND OrderDate >= @fromDate AND OrderDate <= @toDate