I have a view which returns data in below format and I want that to be UPSERTED into a table in addition to that I want the row values loaded into new column in JSON structure. JSON structure need to be formed based on ID and NAME column and the rest need to be array inside JSON.
I want the values to be loaded into target table as similar to above additionally need JSON structured values to be formed by grouping on ID and NAME column and loaded into JSON column which is variant type.
Sample Target table
Sample JSON column value need to be populated for JSON1, JSON2 and JSON 3 are below. Any help to achieve the desired result is much appreciated. Thanks
JSON1
[
{
"col1": "1",
"col2": "TEST001",
"war_detail":[
{ "War_id": "WR001",
"War_start_date": "1/1/1970",
"War_end_date": "12/12/9999"
}
],
"Con_details": [
{ "Cont_id": "CON001",
"Con_start_date": "1/1/1970",
"Con_end_date": "12/12/9999"
},
{ "Cont_id": "CON002",
"Con_start_date": "1/1/2000",
"Con_end_date": "12/12/9999"
}
]
},
{
"col1": "9",
"col2": "TEST001",
"war_detail":[
{ "War_id": "WR001",
"War_start_date": "1/1/1970",
"War_end_date": "12/12/9999"
}
],
"Con_details": [
{ "Cont_id": "CON123",
"Con_start_date": "1/1/2010",
"Con_end_date": "12/12/9999"
}
]
},
]
---------------------------------------
JSON2
[
JSON:{
"col1": "2",
"col2": "TEST002",
"war_detail":[
{ "War_id": "WR987",
"War_start_date": "1/1/1970",
"War_end_date": "12/12/9999"
},
{ "War_id": "WR123",
"War_start_date": "1/1/1990",
"War_end_date": "12/12/9999"
}
],
"Con_details": [
{ "Cont_id": "CON003",
"Con_start_date": "1/1/2020",
"Con_end_date": "12/12/9999"
}
]
}
]
---------------------------------------
JSON3
[
JSON:{
"col1": "2",
"col2": "TEST002",
"war_detail":[
{ "War_id": "WR678",
"War_start_date": "1/1/2001",
"War_end_date": "12/12/2023"
},
{ "War_id": "WR004",
"War_start_date": "1/1/2010",
"War_end_date": "12/12/2030"
}
],
"Con_details": []
}
]