I want to save the data of JSON file which is in my local path to a SQL table.
My Local Path where the JSON file is present is E:\20180824LocalDump.json
I have used the below code in SQL to get the data from JSON file but I got errors.
DECLARE @Details VARCHAR(MAX)
SELECT @Details = BulkColumn FROM OPENROWSET(BULK 'E:\20180824LocalDump.json', SINGLE_BLOB) JSON;
SELECT * FROM OPENJSON(@Details)
WITH(Departure_airport nvarchar(50) ,
DisplayName nvarchar(40),
Email nvarchar(60),
Keep_me_deals nvarchar(40),
Phone_Code nvarchar(50),
Provider nvarchar(50),
SignUpDate nvarchar(50),
Telephone nvarchar(50),
[Platform] nvarchar(50),
AppVersion nvarchar(40))
Created a table as shown below:
Create Table Dump
(
Departure_airport nvarchar(50),
DisplayName nvarchar(40),
Email nvarchar(60),
Keep_me_deals nvarchar(40),
Phone_Code nvarchar(50),
Provider nvarchar(50),
SignUpDate nvarchar(50),
Telephone nvarchar(50),
[Platform] nvarchar(50),
AppVersion nvarchar(40)
)
My Json file contents:
[{"Departure_airport":"Test","DisplayName":"Test","Email":"Tst","Keep_me_deals":"Test","Phone_Code":"Test","Provider":"Test","SignUpDate":"Test","Telephone":"Test","Platform":"Test","AppVersion":"Test"},{"Departure_airport":"Test","DisplayName":"Test","Email":"Tst","Keep_me_deals":"Test","Phone_Code":"Test","Provider":"Test","SignUpDate":"Test","Telephone":"Test","Platform":"Test","AppVersion":"Test"},{"Departure_airport":"Test for IE","DisplayName":"Test for IE","Email":"Tst for IE","Keep_me_deals":"Test for IE","Phone_Code":"Test for IE","Provider":"Test for IE","SignUpDate":"Test for IE","Telephone":"Test for IE","Platform":"Test for IE","AppVersion":"Test for IE"},{"Departure_airport":"Test for UK","DisplayName":"Test for UK","Email":"Tst for UK","Keep_me_deals":"Test for UK","Phone_Code":"Test for UK","Provider":"Test for UK","SignUpDate":"Test for UK","Telephone":"Test for UK","Platform":"Test for UK","AppVersion":"Test for UK"},{"Departure_airport":"Test for UK 1","DisplayName":"Test for UK 1","Email":"Tst for UK 1","Keep_me_deals":"Test for UK 1","Phone_Code":"Test for UK 1","Provider":"Test for UK 1","SignUpDate":"Test for UK 1","Telephone":"Test for UK 1","Platform":"Test for UK 1","AppVersion":"Test for UK 1"}]
I am getting an error like:
Invalid object name 'OPENJSON' in SQL.
Please help me on this
OPENJSONonly works starting from version 2016