Reputation: 141
I have a document which has 2 list attributes
{
CurrentDocument:[
{ DocName: "name1", DocType: "Identity" },
{ DocName: "name2", DocType: "Authorization" }
],
ClosedDocument:[
{ DocName: "name3", DocType: "Passport" }
]
}
I want to have a query that return DocName & DocType of my two lists. I can't use Join because if one of the list is empty, my query return nothing. Furthermore, in case of a join, I can't merge all my attributes in one list.
SELECT cur.DocName AS curName, clo.DocName AS cloName FROM c JOIN cur IN c.CurrentDocument JOIN clo IN c.ClosedDocument
This query is not what I'm looking for cause :
I tried using the Union expression, but i can't seem to make it work in a query.
Thanks in advance.
Upvotes: 0
Views: 397
Reputation: 393
Use UDF for this. Create the following UDF
function userDefinedFunction(current, closed){
return current.concat(closed);}
Use it in your query
SELECT udf.MergeLists(o.CurrentDocument, o.ClosedDocument) as merged FROM Orders o WHERE o.id = 'a811d13f-a308-4df1-85c1-31e566e9fc1e'
This returns the following
Upvotes: 1