Чтение данных из документа иерархии в SQL Server - PullRequest
2 голосов
/ 13 июня 2019

Я использую SQL Server 2016 и разрабатываю пакеты служб SSIS.Я звоню в веб-службу, и у меня есть файл ниже.

{
    "id": "Voyage",
    "fields": {
        "CommenceDateGmt": "2018-10-09T04:00:00",
        "CommenceDateLocal": "2018-10-09T15:00:00",
        "CompleteDateGmt": "2018-11-02T10:30:00",
        "CompleteDateLocal": "2018-11-02T20:30:00",
        "VoyageStatus": "Completed"
    },
    "dataSources": [
        {
            "id": "VoyageItineraries",
            "joinType": "toMany",
            "values": [
                {
                    "fields": {
                        "VesselCode": "aaaa",
                        "VoyageNo": 10000,
                        "Seq": 258,
                        "PortFunc": "C",
                        "PortName": "aaaa (A)"
                    },
                    "dataSources": [
                        {
                            "id": "VoyageItineraryBerths",
                            "joinType": "toMany",
                            "values": [
                                {
                                    "fields": {
                                        "BerthShortName": "aaaa"
                                    }
                                }
                            ]
                        },
                        {
                            "id": "VoyageCargoHandlings",
                            "joinType": "toMany",
                            "values": []
                        },
                        {
                            "id": "Vessel",
                            "joinType": "toOne",
                            "fields": {
                                "Name": "aaasss"
                            }
                        }
                    ]
                },
                {
                    "fields": {
                        "VesselCode": "www",
                        "VoyageNo": 5454,
                        "Seq": 5454,
                        "PortFunc": "L54",
                        "PortName": "54545"
                    },
                    "dataSources": [
                        {
                            "id": "VoyageItineraryBerths",
                            "joinType": "toMany",
                            "values": [
                                {
                                    "fields": {
                                        "BerthShortName": "fsfsdsd&S"
                                    }
                                }
                            ]
                        },
                        {
                            "id": "VoyageCargoHandlings",
                            "joinType": "toMany",
                            "values": [
                                {
                                    "fields": {
                                        "NominatedLiftQty": 54545.0,
                                        "CargoShortName": "dfdfdf"
                                    }
                                }
                            ]
                        },
                        {
                            "id": "Vessel",
                            "joinType": "toOne",
                            "fields": {
                                "Name": "dfewff"
                            }
                        }
                    ]
                },
                {
                    "fields": {
                        "VesselCode": "sdfsdf",
                        "VoyageNo": 23423,
                        "Seq": 234,
                        "PortFunc": "Dd",
                        "PortName": "fewffe"
                    },
                    "dataSources": [
                        {
                            "id": "VoyageItineraryBerths",
                            "joinType": "toMany",
                            "values": [
                                {
                                    "fields": {
                                        "BerthShortName": "erwerwer"
                                    }
                                }
                            ]
                        },
                        {
                            "id": "VoyageCargoHandlings",
                            "joinType": "toMany",
                            "values": [
                                {
                                    "fields": {
                                        "NominatedLiftQty": 23423.0,
                                        "CargoShortName": "sdfsdf"
                                    }
                                },
                                {
                                    "fields": {
                                        "NominatedLiftQty": 23423.0,
                                        "CargoShortName": "sdefsdf"
                                    }
                                }
                            ]
                        },
                        {
                            "id": "Vessel",
                            "joinType": "toOne",
                            "fields": {
                                "Name": "dfsdf"
                            }
                        }
                    ]
                },
                {
                    "fields": {
                        "VesselCode": "dfsdf",
                        "VoyageNo": 234,
                        "Seq": 32433,
                        "PortFunc": "L",
                        "PortName": "sdfsdf"
                    },
                    "dataSources": [
                        {
                            "id": "VoyageItineraryBerths",
                            "joinType": "toMany",
                            "values": [
                                {
                                    "fields": {
                                        "BerthShortName": "sdfsdf"
                                    }
                                }
                            ]
                        },
                        {
                            "id": "VoyageCargoHandlings",
                            "joinType": "toMany",
                            "values": [
                                {
                                    "fields": {
                                        "NominatedLiftQty": 234234.0,
                                        "CargoShortName": "sdfsdf"
                                    }
                                }
                            ]
                        },
                        {
                            "id": "Vessel",
                            "joinType": "toOne",
                            "fields": {
                                "Name": "sdfsdf"
                            }
                        }
                    ]
                }
            ]
        },
        {
            "id": "Cargos",
            "joinType": "toMany",
            "values": [
                {
                    "fields": {
                        "CoaNo": "sdfsdf"
                    },
                    "dataSources": [
                        {
                            "id": "Counterparty",
                            "joinType": "toOne",
                            "fields": {
                                "FullName": "sdfsdfsd"
                            }
                        }
                    ]
                }
            ]
        }
    ]
}
]   

Как видите, у меня есть несколько таблиц.

Мне нужно перенести эти данные иерархии в таблицу.

    Table1Filed1, Table1Filed2, Table1Filed3, Table1Filed4, Table2Field1, Table2Field2, Table2Field3
    Data        , Data        , Data        , Data        , Data        , Data        , Data 
    Data        , Data        , Data        , Data        , Data        , Data        , Data 
    Data        , Data        , Data        , Data        , Data        , Data        , Data 

    Data        , Data        , Data        , Data        , Data        , Data        , Data 
    Data        , Data        , Data        , Data        , Data        , Data        , Data 
...