Calling a web service from SQL

 

declare @out varchar(max)
--text to send to the web service
set @out = 'text to send to web service'
--the text can be XML
set @out = '<content>the text can be XML</content>'
--or JSON
set @out = '{
    "id": 1,
    "name": "A green door",
}'
 
 
Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
  
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',@out, 'false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
  
Select @ResponseText

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences