Created
July 30, 2016 20:06
-
-
Save swbuehler/0b2f5dea9a86648dd7a2bfbb98163700 to your computer and use it in GitHub Desktop.
SQL Server 2016: Stored Procedure to pull data from a JSON text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create procedure [dbo].[InsertFollowers] | |
AS | |
BEGIN | |
truncate table dbo.followers | |
INSERT INTO dbo.followers | |
SELECT k.* | |
FROM OPENROWSET (BULK 'C:\temp\missellacronin.json', SINGLE_NCLOB) as j | |
CROSS APPLY OPENJSON(BulkColumn, '$') | |
WITH ( | |
created_at datetimeoffset, | |
notifications bit, | |
_id int '$.user._id', | |
name nvarchar(50) '$.user.name', | |
user_created_at datetimeoffset '$.user.created_at', | |
user_updated_at datetimeoffset '$.user.updated_at', | |
display_name nvarchar(50) '$.user.display_name', | |
link nvarchar(255) '$.user._links.self', | |
logo nvarchar(255) '$.user.logo', | |
bio nvarchar(max) '$.user.bio' | |
) as k | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment