0

I am not familiar with importing JSON files. I received the code below to import a JSON file but I do not know where to find the data once it is imported? Can someone tell me where the file would be imported to, like the table name from the code? Thanks.

DECLARE @JSON varchar(max)

SELECT @JSON = BulkColumn
FROM OPENROWSET (BULK 'C:\SQL\Walt\ClientReportData_02172024_012817.json', SINGLE_CLOB) import

SELECT *
FROM OPENJSON (@JSON)
WITH (
--Company:
CompanyKey_Company varchar (255) '$.Company.CompanyKey'
,CompanyName varchar (255) '$.Company.CompanyName'
,EIN varchar (255) '$.Company.EIN'
,MaNumber varchar (255) '$.Company.MaNumber'
,ServiceLocation varchar (255) '$.Company.ServiceLocation'

,ProcJson NVARCHAR(MAX) '$.Procedures' AS JSON
) AS oj

OUTER APPLY
        OPENJSON(oj.ProcJson)
            WITH
            (
            --Procedures:
,CompanyKey_Proc varchar (255) '$.CompanyKey'
,ClientKey_Proc varchar (255) '$.ClientKey'
,ClaimKey_Proc varchar (255) '$.ClaimKey'
,ProcedureCode varchar (255) '$.ProcedureCode'
,PlaceOfService varchar (255) '$.PlaceOfService'
,FundingType varchar (255) '$.FundingType'
,IsResidential varchar (255) '$.IsResidential'
,CostCenter varchar (255) '$.CostCenter'
,DenialCode varchar (255) '$.DenialCode'
,UnitOfMeasure varchar (255) '$.UnitOfMeasure'
,PaidUnits varchar (255) '$.PaidUnits'
,Rate varchar (255) '$.Rate'
) 
3
  • 3
    It's not anywhere, as you aren't inserting it into anything; you're reading the file into a variable and then turning that data into a dataset, but it's not being stored in SQL Server.
    – Thom A
    Commented Jul 8 at 17:15
  • Nowhere, you just select the data, it's not imported. Create a table or change your code into: select * into someTableName FROM OPENJSON (@JSON) ... rest of the code Commented Jul 8 at 17:16
  • 1
    Or better: CREATE TABLE with some pre-defined columns, then INSERT YourTable (ColumnsHere) SELECT ... Commented Jul 8 at 19:47

1 Answer 1

0

Your query almost ready for sql table. Just add the INTO JSON_SQLTABLE
statement line into query. I added with a comment. Copy, past and execute modified query. Then open JSON_SQLTABLE

DECLARE @JSON varchar(max)

SELECT @JSON = BulkColumn
FROM OPENROWSET (BULK 'C:\SQL\Walt\ClientReportData_02172024_012817.json', SINGLE_CLOB) import

SELECT *
INTO JSON_SQLTABLE  -- you can just add this line 
FROM OPENJSON (@JSON)
WITH (
--Company:
CompanyKey_Company varchar (255) '$.Company.CompanyKey'
,CompanyName varchar (255) '$.Company.CompanyName'
,EIN varchar (255) '$.Company.EIN'
,MaNumber varchar (255) '$.Company.MaNumber'
,ServiceLocation varchar (255) '$.Company.ServiceLocation'

,ProcJson NVARCHAR(MAX) '$.Procedures' AS JSON
) AS oj

OUTER APPLY
        OPENJSON(oj.ProcJson)
            WITH
            (
            --Procedures:
,CompanyKey_Proc varchar (255) '$.CompanyKey'
,ClientKey_Proc varchar (255) '$.ClientKey'
,ClaimKey_Proc varchar (255) '$.ClaimKey'
,ProcedureCode varchar (255) '$.ProcedureCode'
,PlaceOfService varchar (255) '$.PlaceOfService'
,FundingType varchar (255) '$.FundingType'
,IsResidential varchar (255) '$.IsResidential'
,CostCenter varchar (255) '$.CostCenter'
,DenialCode varchar (255) '$.DenialCode'
,UnitOfMeasure varchar (255) '$.UnitOfMeasure'
,PaidUnits varchar (255) '$.PaidUnits'
,Rate varchar (255) '$.Rate'
) 

Not the answer you're looking for? Browse other questions tagged or ask your own question.