SQL Server IMKB Döviz Bilgileri Çekmek

CREATE PROC DoviKuruAktar
AS


DECLARE @URL AS VARCHAR(8000)
SET @URL=’http://www.tcmb.gov.tr/kurlar/today.xml’

DECLARE @OBJ AS INT
DECLARE @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 #XML
(STRXML VARCHAR(MAX))
INSERT INTO #XML(STRXML) EXEC @RESULT=SP_OAGetProperty @OBJ,’responseXML.xml’

DECLARE @XML AS XML
SELECT @XML=STRXML FROM #XML
SELECT @XML
–DROP TABLE #XML

DECLARE @HDOC AS INT
EXEC SP_XML_PREPAREDOCUMENT @HDOC OUTPUT,@XML
–select @hdoc

SELECT * FROM OPENXML(@HDOC,’Tarih_Date/Currency’)
WITH
(Unit VARCHAR(50) ‘Unit’,
Isim VARCHAR(100) ‘Isim’,
CurrencyName VARCHAR(100) ‘CurrencyName’,
ForexBuying FLOAT ‘ForexBuying’,
ForexSelling FLOAT ‘ForexSelling’,
BanknoteBuying FLOAT ‘BanknoteBuying’,
BanknoteSelling FLOAT ‘BanknoteSelling’)

SELECT * FROM #XML
EXEC DoviKuruAktar

Not: Query doğru çalışması için Ole Automation Procedurleri Aktif Hale getirmemiz gerekli.

  1. sp_configure ‘show advanced options’ , 1
  2. reconfigure with override
  3. sp_configure ‘Ole Automation Procedures’ , 1
  4. reconfigure with override

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir