SQL find specific nodes and return their values (json) as excel formatted results - sql

There is a xml column (ArrayOfString) with json string results. I need to find specific nodes and get their value.
<ArrayOfstring xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>
[report_submit_1, {
"total": 14,
"report": [
{
"date": "11/02/2018",
etc...
},
{
"date": "01/02/2019",
etc...
},
{
"date": "12/12/2018",
etc...
},
etc...
]
}]
</string>
<string>
[something_else, {
"total": 1,
"report": [
{
"date": "12/15/2018",
etc...
},
{
"date": "03/25/2019",
etc...
},
{
"date": "04/12/2019",
etc...
},
etc...
]
}]
</string>
<string>
[report_submit_2, {
"total": 22,
"report": [
{
"date": "05/22/2019",
etc...
},
{
"date": "01/02/2019",
etc...
},
{
"date": "12/12/2018",
etc...
},
etc...
]
}]
</string>
</ArrayOfstring>
SELECT
Xml.value('(.[1])', 'VARCHAR(MAX)') AS Results
FROM tableA
WHERE Xml.exist('(/ns:ArrayOfString/ns:string[contains(.,"report_submit")])') = 0
Would like this 'parsed' as xls style in sql results, so it can be saved off as an excel file with headers

Related

Xero Profit and Loss API - Parse JSON response to SQL Table not working

I am working in ASP .Net MVC, i used Xero nugut package to call api, i can not able to parse json Response .
`I am stuck on how to expand the JSON lists of arrays as columns instead of rows. Please help to retrive data from json to SQL table or in C#, Also i want to display report in html form with this data.
List in Header row Cells column
List in the two Section rows Rows.1 column
Any tips, hints, ideas, pointers?
{
"Reports": [
{
"ReportID": "ProfitAndLoss",
"ReportName": "Profit and Loss",
"ReportType": "ProfitAndLoss",
"ReportTitles": [
"Profit & Loss",
"Demo Company (AU)",
"1 February 2018 to 28 February 2018"
],
"ReportDate": "25 February 2018",
"UpdatedDateUTC": "\/Date(1519593468971)\/",
"Rows": [
{
"RowType": "Header",
"Cells": [
{ "Value": "" },
{ "Value": "28 Feb 18" },
{ "Value": "28 Jan 18" }
]
},
{
"RowType": "Section",
"Title": " Income",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Sales",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
},{
"Value": "9220.05",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
},{
"Value": "5120.05",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
}
]
},
{
"RowType": "SummaryRow",
"Cells": [
{ "Value": "Total Income" },
{ "Value": "9220.05" },
{ "Value": "1250.09" }
]
}
]
},{
"RowType": "Section",
"Rows": [
{
"RowType": "Row",
"Cells": [
{ "Value": "NET PROFIT" },
{ "Value": "-6250.09" },
{ "Value": "-7250.09" }
]
}
]
}
]
}
]
}
`

GA4 data api - (not set) in custom dimensions

We are currently using GA4 data API and faced the issue when custom dimensions returns value "(not set)".
We were using the following article to set custom dimension for the session count, but we still receiving "(not set)" values.
Example of request:
{
"dateRanges": [
{
"startDate": "2021-09-01",
"endDate": "2021-09-05"
}
],
"offset": 0,
"limit": 100,
"dimensionFilter": {
"filter": {
"fieldName": "eventName",
"stringFilter": {
"matchType": 1,
"value": "screen_view",
"caseSensitive": true
}
}
},
"dimensions": [
{
"name": "customUser:applicationID"
},
{
"name": "customEvent:ga_session_number"
},
{
"name": "dateHour"
},
{
"name": "platform"
},
{
"name": "sessionSource"
},
{
"name": "sessionMedium"
},
{
"name": "sessionCampaignName"
},
{
"name": "deviceCategory"
}
],
"metrics": [
{
"name": "userEngagementDuration"
}
]
}
Does anybody have any idea why it may happen?

Ramda - Pick from an object and return an array

I have an array of ids which I need to use to get extended information from an object so it looks like this:
const arrayOne = [1, 2]
const objectOne =
{
"1": {
"id": 1,
"reference": "ee",
"content": {
"blocks": [
{
"type": "plain",
"data": {
"text": "Lorem2"
}
}
]
}
},
"2": {
"id": 2,
"reference": "dd",
"content": {
"blocks": [
{
"type": "plain",
"data": {
"text": "Lorem"
}
}
]
}
},
"3": {
"id": 3,
"reference": "dd",
"content": {
"blocks": [
{
"type": "plain",
"data": {
"text": "Lorem"
}
}
]
}
}
}
Then I am using Ramda to get only ids from arrays like this:
R.pick(arrayOne)(objectOne)
but then I get object and what I need is an array. How can I convert it?
In this case you probably need props instead:
Acts as multiple prop: array of keys in, array of values out. Preserves order.
props(['1', '2'], {1: "foo", 2: "bar"});
//=>["foo","bar"]

Mongo DB query: project array element to property

Having following data
{
"_id": "...",
"name": "John",
"purchases": [
{
"date": {
"$date": "2016-12-20T00:00:00.000Z"
},
"amount": 1000
},
{
"date": {
"$date": "2016-12-23T00:00:00.000Z"
},
"amount": 100
}
]
}
How to get latest purchase amount as result field with different name?
To get next result:
{
"_id": "...",
"name": "John",
"purchases": [
{
"date": {
"$date": "2016-12-20T00:00:00.000Z"
},
"amount": 1000
},
{
"date": {
"$date": "2016-12-23T00:00:00.000Z"
},
"amount": 100
}
]
},
"latestPurchaseAmount": 100
}
You have to use the $rename take a look at this link
And for your last item you should look at this it will helps you Link
You can do something like this. This below query will unwind all the purchases in the collection and, sort the purchases by date descending and, limit the result to one and project the corresponding amount.
db.purchases.aggregate([{
$unwind: "$purchases"
}, {
$sort: {
"purchases.date": -1
}
}, {
$limit: 1
}, {
$project: {
_id: 0,
latestPurchaseAmount: "$purchases.amount"
}
}]);
Output
{ "latestPurchaseAmount" : 100 }

Need to get the following query to output correctly

Hi guys I've been trying all day to construct this simple mongo query but I can't get the desire output. Below is the query and the current output.
db.customers.aggregate(
{ $match : { "status" : "Closed" } },
{ $unwind: "$lines" },
{ $group : {
_id:{label: "$lines.label",date: {$substr: [ "$date", 0, 10 ]}},
values: { $push: { date: {$substr: [ "$date", 0, 10 ]}} },
count: { $sum: 1 }
}},
{ $project : {
_id : 1,
values:1,
count:1
}}
);
Which outputs the following.
{
"result": [
{
"_id": {
"label": "label",
"date": "2010-10-01"
},
"values": [
{
"date": "2010-10-01"
},
{
"date": "2010-10-01"
},
{
"date": "2010-10-01"
},
{
"date": "2010-10-01"
}
],
"count": 4
},
{
"_id": {
"label": "label",
"date": "2010-10-10"
},
"values": [
{
"date": "2010-10-10"
}
],
"count": 1
},
{
"_id": {
"label": "label",
"date": "2010-07-25"
},
"values": [
{
"date": "2010-07-25"
}
],
"count": 1
}
]
}
However the output below is the one that I'm looking for and just can't get. I can obviously get all the data I desire, just in the wrong places.
{
"result": [
{
"_id": "label",
"values": [
{
"date": "2010-11-27",
"count": 4
},
{
"date": "2010-10-10",
"count": 1
},
{
"date": "2010-07-25",
"count": 1
}
]
}
]
}
Like always thanks for the help and support.
Can you try this:
db.customers.aggregate([
{ $match : { "status" : "Closed" } },
{ $unwind: "$lines" },
{ $group : {
_id:{label: "$lines.label",date: {$substr: [ "$date", 0, 10 ]}},
values: { $push: { date: {$substr: [ "$date", 0, 10 ]}} },
count: { $sum: 1 }
}},
// This one I added to group them behind a single label in an array list
{ $group : {
_id:{
label: "$_id.label"
},
values : {
$push : { date : "$date", count : "$count" }
}
}
},
{ $project : {
_id : 1,
values:1,
count:1
}
}
]);
If I got your problem right, you like to group the counts + dates in an values array. That you can do with $push after the 1st group stage.