Sometimes it is needed to convert posts from the primary currency to a
different one (for example, for financial reports. The following SQL query
performs the conversion. You have to specify the target currency and the
PANTHEON subject with the exchange rate.
declare
@cKljuc char(11),
@iPoz int,
@fDebet money,
@fKredit money,
@fTecaj money,
@cValuta char(3),
@dDatum datetime
set nocount on
set @cValuta = 'EUR' -- currency to convert to
declare crKurzor cursor local fast_forward for
select KLJUC,POZ,DEBET,KREDIT,DATUMDOK
from TEMEPOZ
where VALUTA <> @cValuta
and -- SPECIFY WHICH POSTS TO CONVERT
open crKurzor
fetch next from crKurzor into @cKljuc, @iPoz, @fDebet, @fKredit, @dDatum
while @@fetch_status = 0
begin
-- the first argument is the subject with the exchange rate you wish to use for the conversion
exec dl_PoisciTecaj 'Central rate','EUR',@dDatum,@fTecaj output
update TEMEPOZ
set VALUTA = @cValuta,
DEVTEC = @fTecaj,
VALDEBET = @fDebet / @fTecaj,
VALKREDIT = @fKredit / @fTecaj
where KLJUC = @cKljuc
and POZ = @iPoz
fetch next from crKurzor into @cKljuc, @iPoz, @fDebet, @fKredit, @dDatum
end
close crKurzor
deallocate crKurzor