Skip to content

Instantly share code, notes, and snippets.

@swbuehler
Created July 30, 2016 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swbuehler/0b2f5dea9a86648dd7a2bfbb98163700 to your computer and use it in GitHub Desktop.
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
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