Avatar of Leo Torres
Leo Torres
Flag for United States of America

asked on 

Query Json file

I wan to query the Ticker, Status,queryCount, adjusted columns but I can't seem to be able to query the values inside result with the values outside that variable.


SELECT tbl.*
FROM OPENROWSET (BULK 'C:\SomeFile.json', SINGLE_CLOB) js
CROSS APPLY OPENJSON(BulkColumn)
WITH
(
	v NVARCHAR(MAX) '$.results' AS JSON
	
)
cross APPLY OPENJSON(v)
WITH
(
	
	[v] int,
	[vw] decimal(15,5),
	[o] decimal(15,5),
	[c] decimal(15,5),
	[h] decimal(15,5),
	[l] decimal(15,5),
	[t] bigint,
	[n] smallint
) tbl

Open in new window





this is my json file below

[{
        "ticker": "VIG",
        "status": "OK",
        "queryCount": 1571,
        "resultsCount": 1571,
        "adjusted": false,
        "results": [{
                "v": 117,
                "vw": 112.0438,
                "o": 112,
                "c": 112,
                "h": 112,
                "l": 112,
                "t": 1588330800000,
                "n": 5
            }

Open in new window

Microsoft SQL ServerJSONSQL

Avatar of undefined
Last Comment
ste5an

8/22/2022 - Mon