SSRS Expression-Sum two fields - sql-server

I need to sum two fields but I couldn't.
Can you help me?
=iif(Fields!ABC.Value= "", Nothing, Sum(Fields!PA.Value))
=iif(Fields!XYZ.Value= "", Nothing, Sum(Fields!PA.Value))
It does not work that way:
=iif(Fields!ABC.Value= "", Nothing, Sum(Fields!PA.Value)) +
iif(Fields!XYZ.Value= "", Nothing, Sum(Fields!PA.Value))

To sum them I should think you just want to default to 0 rather than Nothing
=iif(Fields!ABC.Value= "", 0, Sum(Fields!PA.Value)) +
iif(Fields!XYZ.Value= "", 0, Sum(Fields!PA.Value))

I think what he is looking for is something like this:
=Sum(IIF(Fields!ABC.Value = "", Nothing, Fields!PA.Value)
=Sum(IIF(Fields!XYZ.Value = "", Nothing, Fields!PA.Value)

Related

Neo4j: Do queries on specific database?

I´m new to Neo4j, and want to implement a service that makes use of it.
I´ve read the docs and searched for it, however I still didn´t get an answer to this simple question:
How do I specify which database to query in a Neo4j query?
E.g. I connected to bolt://localhost:7687, and have three databases in there: system, neo4j, and mydb. The neo4j database is the standard.
When I open the Neo4j browser and do a query such as MATCH (n) RETURN n, it automatically assumes that I want to query the standard DB which is called neo4j. However, I want to query another one, mydb.
My output when I query aforementioned query says
{
"query": {
"text": "match (n) return n",
"parameters": {}
},
"queryType": "r",
"counters": {
"_stats": {
"nodesCreated": 0,
"nodesDeleted": 0,
"relationshipsCreated": 0,
"relationshipsDeleted": 0,
"propertiesSet": 0,
"labelsAdded": 0,
"labelsRemoved": 0,
"indexesAdded": 0,
"indexesRemoved": 0,
"constraintsAdded": 0,
"constraintsRemoved": 0
},
"_systemUpdates": 0
},
"updateStatistics": {
"_stats": {
"nodesCreated": 0,
"nodesDeleted": 0,
"relationshipsCreated": 0,
"relationshipsDeleted": 0,
"propertiesSet": 0,
"labelsAdded": 0,
"labelsRemoved": 0,
"indexesAdded": 0,
"indexesRemoved": 0,
"constraintsAdded": 0,
"constraintsRemoved": 0
},
"_systemUpdates": 0
},
"plan": false,
"profile": false,
"notifications": [],
"server": {
"address": "localhost:7687",
"version": "Neo4j/4.4.5",
"agent": "Neo4j/4.4.5",
"protocolVersion": 4.4
},
"resultConsumedAfter": {
"low": 2,
"high": 0
},
"resultAvailableAfter": {
"low": 8,
"high": 0
},
"database": {
"name": "neo4j"
}
}
In the last JSON value is the proof that the query was executed on database neo4j.
What do I have to add to my queries to instead query another database in the same DBMS?
You can change/specify the database using the following options.
From the Neo4j Browser, you can select the database in the sidebar.
In Cypher syntax, the use command lets you choose different databases.
:use mydb.
If you connect to Neo4j through an Application driver, you can specify the database while creating the session object.
For example, if you are using the Python driver:
from neo4j import GraphDatabase
driver = GraphDatabase.driver(uri, auth=(user, password))
session = driver.session(database="mydb")
Specify the default database in a system-wide manner by modifying the config_dbms.default_database value in the the neo4j.conf file.

Formatting into CSV JSON file using jq

I've some data in a file called myfile.json. I need to format using jq - in JSON it looks like this ;
{
"result": [
{
"service": "ebsvolume",
"name": "gtest",
"resourceIdentifier": "vol-999999999999",
"accountName": "g-test-acct",
"vendorAccountId": "12345678912",
"availabilityZone": "ap-southeast-2c",
"region": "ap-southeast-2",
"effectiveHourly": 998.56,
"totalSpend": 167.7,
"idle": 0,
"lastSeen": "2018-08-16T22:00:00Z",
"volumeType": "io1",
"state": "in-use",
"volumeSize": 180,
"iops": 2000,
"throughput": 500,
"lastAttachedTime": "2018-08-08T22:00:00Z",
"lastAttachedId": "i-086f957ee",
"recommendations": [
{
"action": "Rightsize",
"preferenceOrder": 2,
"risk": 0,
"savingsPct": 91,
"savings": 189.05,
"volumeType": "gp2",
"volumeSize": 120,
},
{
"action": "Rightsize",
"preferenceOrder": 4,
"risk": 0,
"savingsPct": 97,
"savings": 166.23,
"volumeType": "gp2",
"volumeSize": 167,
},
{
"action": "Rightsize",
"preferenceOrder": 6,
"risk": 0,
"savingsPct": 91,
"savings": 111.77,
"volumeType": "gp2",
"volumeSize": 169,
}
]
}
}
I have it formatted better with the following
jq '.result[] | [.service,.name,.resourceIdentifier,.accountName,.vendorAccountId,.availabilityZone,.region,.effectiveHourly,.totalSpend,.idle,.lastSeen,.volumeType,.state,.volumeSize,.iops,.throughput,.lastAttachedTime,.lastAttachedId] |#csv' ./myfile.json
This nets the following output ;
"\"ebsvolume\",\"gtest\",\"vol-999999999999\",\"g-test-acct\",\"12345678912\",\"ap-southeast-2c\",\"ap-southeast-2\",998.56,167.7,0,\"2018-08-16T22:00:00Z\",\"io1\",\"in-use\",180,2000,500,\"2018-08-08T22:00:00Z\",\"i-086f957ee\""
I figured out this but its not exactly what I am trying to achieve. I want to have each recommendation listed underneath on a seperate line, and not at the end of the same line.
jq '.result[] | [.service,.name,.resourceIdentifier,.accountName,.vendorAccountId,.availabilityZone,.region,.effectiveHourly,.totalSpend,.idle,.lastSeen,.volumeType,.state,.volumeSize,.iops,.throughput,.lastAttachedTime,.lastAttachedId,.recommendations[].action] |#csv' ./myfile.json
This nets :
"\"ebsvolume\",\"gtest\",\"vol-999999999999\",\"g-test-acct\",\"12345678912\",\"ap-southeast-2c\",\"ap-southeast-2\",998.56,167.7,0,\"2018-08-16T22:00:00Z\",\"io1\",\"in-use\",180,2000,500,\"2018-08-08T22:00:00Z\",\"i-086f957ee\",\"Rightsize\",\"Rightsize\",\"Rightsize\""
What I want is
"\"ebsvolume\",\"gtest\",\"vol-999999999999\",\"g-test-acct\",\"12345678912\",\"ap-southeast-2c\",\"ap-southeast-2\",998.56,167.7,0,\"2018-08-16T22:00:00Z\",\"io1\",\"in-use\",180,2000,500,\"2018-08-08T22:00:00Z\",\"i-086f957ee\",
\"Rightsize\",
\"Rightsize\",
\"Rightsize\""
So not entirely sure how to deal with the array inside the "recommendations" section in jq, I think it might be called unflattening?
You can try this:
jq '.result[] | [ flatten[] | try(.action) // . ] | #csv' file
"\"ebsvolume\",\"gtest\",\"vol-999999999999\",\"g-test-acct\",\"12345678912\",\"ap-southeast-2c\",\"ap-southeast-2\",998.56,167.7,0,\"2018-08-16T22:00:00Z\",\"io1\",\"in-use\",180,2000,500,\"2018-08-08T22:00:00Z\",\"i-086f957ee\",\"Rightsize\",\"Rightsize\",\"Rightsize\""
flatten does what it says.
try tests if .action is neither null nor false. If so, it emits its value, otherwise jq emits the other value (operator //).
The filtered values are put into an array in order to get them converted with the #csv operator.
That didn't overly work for me actually it omitted all the data in the previous array - but thanks!
I ended up with the following, granted it doesn't put the Rightsize details on a seperate line but it will have to do:
jq -r '.result[] | [.service,.name,.resourceIdentifier,.accountName,.vendorAccountId,.availabilityZone,.region,.effectiveHourly,.totalSpend,.idle,.lastSeen,.volumeType,.state,.volumeSize,.iops,.throughput,.lastAttachedTime,.lastAttachedId,.recommendations[][]] |#csv' ./myfile.json

Read and display CSV in text widget using loop

I have a program that is reading in a csv file and outputting a number of fields into a text widget, my initial hack of allocating variables works fine, but doesnt give me any flexibility to display more than three lines from the csv file, so i need to go down the route of using a loop routine. Unfortunately I'm unsure how to attack this with what I currently have. My hack code follows below.
def checkcsv():
with open("lesspreadsheettest.csv") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
result=(row['Shop Order'])
if sonumber.get() == result:
descQty=(row['Quantity'])
descInfo=(row['Description'])
descPN=(row['Part Number'])
descDwg1=(row['Drawings1'])
descIss1=(row['Issue1'])
descDwg2=(row['Drawings2'])
descIss2=(row['Issue2'])
descDwg3=(row['Drawings3'])
descIss3=(row['Issue3'])
self.outputQty.insert(1.0, descQty)
self.outputDesc.insert(1.0, descPN, "", ": ", "", descInfo)
self.dwgoutputbox.insert(1.0, descDwg3, "dwg", " Issue: ", "", descIss3, "", "\n")
self.dwgoutputbox.insert(1.0, descDwg2, "dwg", " Issue: ", "", descIss2, "", "\n")
self.dwgoutputbox.insert(1.0, descDwg1, "dwg", " Issue: ", "", descIss1, "", "\n")
self.outputQty.configure(state="disabled")
self.outputDesc.configure(state="disabled")
self.dwgoutputbox.configure(state="disabled")
Hmm, to be honest I feel like one of us is missing something quite easy and obvious. I've tweaked your code a little bit. But all I've done is adding one for loop, you'll. Maybe this is what you are looking for.. If not, hopefully we'll be able to specify the problem better:
def checkcsv():
with open("lesspreadsheettest.csv") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
result=(row['Shop Order'])
if sonumber.get() == result:
descQty=(row['Quantity'])
descInfo=(row['Description'])
descPN=(row['Part Number'])
# I've added the following four lines of code
# and commented out some lines, hopefully it is clear
# how to add more descDwg, descIss, simply change the range
# assuming your csv work that way = DrawingsX, IssueX...
for i in xrange(1,4):
descDwg=(row['Drawings'+ str(i)])
descIss=(row['Issue'+ str(i)])
# check, whether the issue is empty if so, skip to the next one
if descIss == '':
continue
self.dwgoutputbox.insert(1.0, descDwg, "dwg", " Issue: ", "", descIss, "", "\n")
# descDwg1=(row['Drawings1'])
# descIss1=(row['Issue1'])
# descDwg2=(row['Drawings2'])
# descIss2=(row['Issue2'])
# descDwg3=(row['Drawings3'])
# descIss3=(row['Issue3'])
self.outputQty.insert(1.0, descQty)
self.outputDesc.insert(1.0, descPN, "", ": ", "", descInfo)
# self.dwgoutputbox.insert(1.0, descDwg3, "dwg", " Issue: ", "", descIss3, "", "\n")
# self.dwgoutputbox.insert(1.0, descDwg2, "dwg", " Issue: ", "", descIss2, "", "\n")
# self.dwgoutputbox.insert(1.0, descDwg1, "dwg", " Issue: ", "", descIss1, "", "\n")
self.outputQty.configure(state="disabled")
self.outputDesc.configure(state="disabled")
self.dwgoutputbox.configure(state="disabled")

Solr fq not eliminating results

I am issuing the following query:
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"q": "(test)",
"defType": "edismax",
"indent": "true",
"fl": "distributor_status,QOH_estimate,id,score",
"start": "0",
"sort": "score desc,id desc",
"fq": "(QOH_estimate:[1 TO *])+OR+(distributor_status:stock)+OR+(*:* -distributor_status:VENDORDISC)",
"rows": "10",
"wt": "json",
"_": "1446833368873"
}
}
I am getting back documents like the following:
{ "id": "5445a000e4b0fb20ffca4aba",
"QOH_estimate": 0,
"distributor_status": "VENDORDISC",
"score": 4.48295
}
How does this document get past the fq?
Its QOH_estimate is 0, so it fails the QOH_estimate:[1 TO *]. Its distributor_status is VENDORDISC, so it fails distribotor_status:stock. Its distributor_status is VENDORDISC, so I would also expect it to fail the (*:* -distributor_status:VENDORDISC) as well. Since it fails all 3 parts of the disjunctive query, I would expect it to be eliminated, yet it is not being eliminated. Why?
I think your spaces between the clauses are double-escaping. Why otherwise, you have +OR+ in that output when the other spaces are fine.
If that does not help, try adding debug flag and see how that all gets parsed into the Lucene level. That should give a hint to the final expansion.

Access JSON array using SuperObject

I have recently switched from using ULKJson to SuperObject and I have been looking around at the examples that come with the package and have made some headway with most it it, but it appears as I have come across a snag. To be more specific, I cannot seem to find an example to show how to access item in an array like the one in the example below.
{
"name": "John Smith",
"tel": 555-5555,
"age": 18,
"height": 1.8,
"place": [{"address": "PO Box 1234", "city": "Florida", "code": 2000},
{"address": "1 Sparrow street", "city": "Florida", "code": 2000}]
}
To access the regular items I use the following code which seems to work just fine.
procedure TForm1.Button1Click(Sender: TObject);
var
SO : ISuperObject;
age, height, tel : Integer;
name : String;
begin
SO := TSuperObject.ParseFile('JSON.txt',true);
name := SO.S['name'];
age := SO.I['age'];
tel := SO.I['tel'];
height := SO.I['height'];
Memo1.Lines.Clear;
Memo1.Lines.Add('Name: ' + name);
Memo1.Lines.Add(#10#13);
Memo1.Lines.Add('Age: ' + age);
Memo1.Lines.Add(#10#13);
Memo1.Lines.Add('Telephone: ' + tel);
Memo1.Lines.Add(#10#13);
Memo1.Lines.Add('Height: ' + height);
Memo1.Lines.Add(#10#13);
end;
However, I am not sure how to access the items in the Place array and I am sure I am just overlooking something simple, but I could not find any examples in the demos which showed how to access this data and was hoping one of the gurus here might be able to offer some assistance or atleast point me to a guide where I can learn from myself.
The way I would do it would be simply:
var
location:ISuperObject;
begin
for location in SO['place'] do
Memo1.Lines.Add(location.S['address']); //etc.
end;
end;
And as TLama has suggested, the short guide really is a great source to learn from.

Resources