UNPIVOT VARIANT data in SQL

binsel
New Contributor III

Hi All,

Have a VARIANT column with the following data;

CREATE TABLE unpivot_valtype AS
SELECT parse_json(
'{
  "Id": 1234567,
  "Result": {
      "BodyType": "NG",
      "ProdType": "Auto",
      "ResultSets": [
        {
        "R1": {
          "AInt": 1,
          "CRates": 
            {
              "RateA": 11,
              "RateB": 12,
              "RateC": 13
            }
          ,
          "EffPrice": 14,
          "EffRate": 15
        },
        "R2": {
          "AInt": 2,
          "CRates": 
            {
              "RateA": 21,
              "RateB": 22,
              "RateC": 23
            }
          ,
          "EffPrice": 24,
          "EffRate": 25
        },
        "R3": {
          "AInt": 3,
          "CRates": 
            {
              "RateA": 31,
              "RateB":32,
              "RateC": 33
            }
          ,
          "EffPrice": 34,
          "EffRate": 35
        } } ]
    }
}') as rowData

and I want to convert "ResultSets" to rows as seen below:

result.png

Not sure how I should flatten it this way.

Thanks,

Burhan