httpwebclient request and insert to sql server

Solutions on MaxInterview for httpwebclient request and insert to sql server by the best coders in the world

showing results for - "httpwebclient request and insert to sql server"
Amy
08 Nov 2019
1-- Query the Stack Overflow API and get a response
2DECLARE @response XML = 
3    [dbo].[clr_http_request]
4        (
5            'GET', 'http://api.stackexchange.com/2.2/questions?site=stackoverflow', 
6            NULL, NULL, 300000, 1, 0
7        );
8-- Extract just the body of the response (expecting JSON)
9DECLARE @response_json NVARCHAR(MAX) = @response.value('Response[1]/Body[1]', 'NVARCHAR(MAX)');
10-- Parse the JSON into a tabular format
11SELECT 
12    B.[question_id],
13    B.[title],
14    B.[tags],
15    B.[is_answered],
16    B.[view_count],
17    B.[answer_count],
18    B.[score]
19FROM OPENJSON(@response_json) WITH ([items] NVARCHAR(MAX) AS JSON) A
20CROSS APPLY OPENJSON(A.[items]) WITH 
21    (
22        [question_id] INT,
23        [title] NVARCHAR(MAX),
24        [tags] NVARCHAR(MAX) AS JSON,
25        [is_answered] BIT,
26        [view_count] INT,
27        [answer_count] INT,
28        [score] INT
29    ) B;
similar questions