CREATE PROCEDURE SP_MBK_EXCHANGE_RATE
AS
BEGIN
DECLARE @URL AS VARCHAR(250) = 'https://www.tcmb.gov.tr/kurlar/today.xml',
@OBJ AS INT,
@RESULT AS INT
EXEC @RESULT = SP_OACREATE 'MSXML2.XMLHttp', @OBJ OUT
EXEC @RESULT = SP_OAMethod @OBJ, 'open', NULL,'GET', @URL, false
EXEC @RESULT = SP_OAMethod @OBJ,SEND,NULL,''
CREATE TABLE #TEMPXML (STRXML VARCHAR(MAX))
INSERT INTO #TEMPXML (STRXML) EXEC @RESULT = SP_OAGetProperty @OBJ,'ResponseXML.xml'
DECLARE @XML AS XML
SELECT @XML = STRXML FROM #TEMPXML
--SELECT @XML
DROP TABLE #TEMPXML
DECLARE @HDOC AS INT
EXEC SP_XML_PREPAREDOCUMENT @HDOC OUTPUT,@XML
-- Tüm veriler siliniyor
DELETE FROM dbMEDIUM.dbo.MBK_EXCHANGE_RATE
-- Veriler yeniden ekleniyor
INSERT dbMEDIUM.dbo.MBK_EXCHANGE_RATE
SELECT * FROM OPENXML(@HDOC,'Tarih_Date/Currency')
WITH
(
Unit VARCHAR(50) 'Unit',
Isim VARCHAR(50) 'Isim',
CurrencyName VARCHAR(50) 'CurrencyName',
ForexBuying FLOAT 'ForexBuying',
ForexSelling FLOAT 'ForexSelling',
BanknoteBuying FLOAT 'BanknoteBuying',
BanknoteSelling FLOAT 'BanknoteSelling'
)
END