Last active
March 3, 2019 17:02
-
-
Save garrytrinder/a4f9ad773d4a88cf69997db1b996dbc2 to your computer and use it in GitHub Desktop.
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
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
-- ============================================= | |
-- Author: Garry Trinder | |
-- Create Date: 17/02/2019 | |
-- Description: Truncates TimeEntry table and imports data from Azure Storage | |
-- ============================================= | |
CREATE PROCEDURE ImportTimeEntries @Run bit | |
AS | |
BEGIN | |
IF @Run <> 1 | |
BEGIN | |
RAISERROR('RUN NOT TRUE', 16, 10) | |
END | |
BEGIN | |
TRUNCATE TABLE [TimeEntry] | |
END | |
BEGIN | |
INSERT INTO [TimeEntry] | |
SELECT [TimeEntry].[EntryDate], | |
[TimeEntry].[Employee], | |
[TimeEntry].[Client], | |
[TimeEntry].[Project], | |
[TimeEntry].[Task], | |
[TimeEntry].[Hours], | |
[TimeEntry].[Notes] | |
FROM OPENROWSET(BULK 'harvestdata/TimeEntries.json', DATA_SOURCE = 'harvestdata001', SINGLE_CLOB) as json | |
CROSS APPLY OPENJSON(BulkColumn) | |
WITH ( [EntryDate] date '$.spent_date', | |
[Employee] varchar(25) '$.user.name', | |
[Client] varchar(50) '$.client.name', | |
[Project] varchar(50) '$.project.name', | |
[Task] varchar(25) '$.task.name', | |
[Hours] float '$.hours', | |
[Notes] varchar(255) '$.notes' | |
) as [TimeEntry] | |
END | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment