Project

General

Profile

Feature #285 » PDSFILOGETEXCHANGERATECURRENCY.sql

Tri Rizqiaty, 06/02/2021 04:18 PM

 
1
??ALTER PROCEDURE [dbo].[PDSFILOGETEXCHANGERATECURRENCY]
2

3
(
4

5
	@CurrencyFrom VARCHAR(20)
6

7
	,@CurrencyTo VARCHAR(20)
8

9
	,@PostingDate VARCHAR(20)
10

11
	,@CompanyID VARCHAR(20)
12

13
	,@ConvertionType VARCHAR(20)
14

15
)
16

17
AS
18

19

20

21
--DECLARE @CurrencyFrom VARCHAR(20) = 'USD'
22

23
--DECLARE @CurrencyTo VARCHAR(20) = 'IDR'
24

25
--DECLARE @PostingDate VARCHAR(20) = '20210531'
26

27
--DECLARE @CompanyID VARCHAR(20) = '1000'
28

29
--DECLARE @ConvertionType VARCHAR(20) = 'FIN'
30

31

32

33
DECLARE @ExchangeRate DECIMAL(22,0)
34

35

36

37
SELECT @ExchangeRate = Amount2/Amount1
38

39
FROM PCMFILOCURRATE AS Cur
40

41
WHERE Cur.ConvertionType = @ConvertionType
42

43
AND Cur.Currency1 = @CurrencyFrom
44

45
AND Cur.Currency2 = @CurrencyTo
46

47
AND Cur.DateRate = @PostingDate
48

49

50

51
IF(@ExchangeRate IS NULL OR @ExchangeRate <= 0)
52

53
BEGIN
54

55
	SELECT TOP(1)  @ExchangeRate = Amount2/Amount1
56

57
	FROM PCMFILOCURRATE AS Cur
58

59
	WHERE Cur.ConvertionType = @ConvertionType
60

61
		AND Cur.Currency1 = @CurrencyFrom
62

63
		AND Cur.Currency2 = @CurrencyTo
64

65
	ORDER BY Cur.DateRate DESC
66

67
END
68

69

70

71
SELECT CONVERT(VARCHAR(22), @ExchangeRate) AS ExchangeRate
(4-4/4)