ORDA: How can I query field value against a field value? - 4d-database

Background
I'm converting old 4D code from class queries to ORDA queries. One thing I can't figure out is how to query with a field vs a field, rather than a field vs a value.
Edit: I'm using 4D v17.4.
Example
Classic:
Query([Customers];[Customers]State="IN")
ORDA:
ds.Customers.query("State = 'IN'")
Goal
I want to be able to query a table for results where I'm comparing a field value vs another field value. I can do it in classic querying via the following:
Query([Customers];[Customers]State#[Customers]AdministrativeRegion)
What I Tried
ds.Customers.query("State # AdministrativeRegion") // DOESN'T WORK
Question
Is this possible?

You didn't mention which version of 4D you are using. 4D is changing very rapidly these days and the difference between them can really matter, though in this case not as much.
Using placeholders in your query string is the first step.
Instead of
ds.Customers.query("State # AdministrativeRegion")
do
ds.Customers.query("State # :1 ";"some value")
Each placeholder is referenced by the :n syntax starting at 1. This is a big benefit because 4D will manage converting the comparison value data type. This is also the key to referencing a value in an entity, object, formula, etc.
$entity_selection:=ds.Customers.query("State # :1";$entity.State)
where $entity is the one you want to compare to.

I would rather use ds.Customers.query(":1";Formula(This.State#This.AdministrativeRegion))

Related

Access Expression help - Calculated fields

I need some help with an Access expression. I keep getting a syntax error.
I'm trying to get a calculated field from the combination of another calculated field.
Note that the LaserCuttingRate field is also a Lookup field. So it's not a simple entry field. It becomes a selector of the 3 choices.
IIf([LaserCuttingRate]="200",([CuttingTime]*200/60),IIf([LaserCuttingRate]="400",([CuttingTime]*400/60),IIf([LaserCuttingRate]="100",([CuttingTime]*100/60)))
All help appreciated.
Cam
I think you're missing a final close bracket.
There are 6 open brackets ( but only 5 closing brackets )
UPDATE - second issue
Two extra issues
The checks on number either don't need, or shouldn't have double-quotation masks
The final IIF also needs a false clause at the end (in the example below, 0).
Try this - I have put it into an Access database scratch table and it worked. (If relevant, note that I had LaserCuttingRate and CuttingTime set as doubles, as well as the Result Type for the calculated column).
IIf([LaserCuttingRate]=200,([CuttingTime]*200/60),IIf([LaserCuttingRate]=400,([CuttingTime]*400/60),IIf([LaserCuttingRate]=100,([CuttingTime]*100/60),0)))

Integrating a parameter inside a SSRS lookup expression?

I am attempting to control the visibility of an error message with the following code:
=IIf((Lookup(Parameters!FA.Value, Fields!fa_num.Value,Fields!LastName.Value,"Advisor_Numbers")=""),False, True)
What this theoretically should do is look at the FA # inputted by the user, then look within the "Advisor_Numbers" dataset for a match in fa_num...and once found to check if the last name of the advisor is empty.
If this is true: return false. Otherwise, return true.
This code always returns false despite the sample FA numbers I use existing in the Advisor_Numbers table. Is my syntax for writing a parameter within a lookup incorrect?
Ideally I'd just like to lookup if the parameter exists within the table without involving the last name.
I found the solution to my own problem.
While everything looked fine on the surface, there was probably some empty space somewhere in my data. Therefore, make sure to use Trim.
=IIf((Lookup(Trim(Parameters!FA.Value),Trim( Fields!fa_num.Value),Trim(Fields!LastName.Value),"Advisor_Numbers")=""),False, True)
The code above worked smoothly and solved all my issues

Change Case in SSRS 2013

I am using a parameter to change the background color of my field when the field string contains the parameter string .
I have used IndexOf, Contains, and instr. All three work, however they are all case sensitive. (i.e. when I search 'Dol' Dollar Tree and Doldrum are highlighted but not Sandolski etc.)
It is not the stored procedure, the correct records display, however the SSRS functions are what is my challenge.
I have tried toLowerInvariant but was receiving an error Help please.
As I was writing this I checked my error and learned the issue..
I assumed the syntax was to pass my string as a parameter:
toLowerInvariant(Parameters!Param1.Value)
However the correct toLowerInvariant syntax is (in ssrs):
Parameters!Param1.Value.toLowerInvariant()
An explaination on toLowerInvariant can be found here: string.ToLower() and string.ToLowerInvariant()
And also I have found that this comparison is best done with a Switch (if you are comparing multiple parameters to the field).
I have not noticed a performance impact between Field.IndexOf(#Param), Field.Contains(#Param), or Field.Instr(#Param)
My final code:
=switch(
instr(Fields!Client.Value.toLowerInvariant(),Parameters!Client_Firm.Value.toLowerInvariant()) >= 1, "Cornsilk",
instr(Fields!Client.Value.toLowerInvariant(),Parameters!KeyWord.Value.toLowerInvariant()) >= 1, "Cornsilk"
)

Comparing the excel cell value while importing in spring

I am importing excel data using html, spring and apache POI API. I need to do some validations before saving the data.
For a cell, I need to check whether its value is greater than 01 and less than 32.
I have seen like
cell.getStringCellValue().matches(regex);
Using this I have reached in a solution like this
if(cell.getStringCellValue().matches("\b([1-9]|[12][0-9]|3[01])\b"))
But I have read like, using regExp for comparing numbers is not such a good Idea, it is mainly for strings.
So my question is , is there a better way to solve my problem, finding whether the cell value falls within a range.
You need to add 0 before [1-9] inorder to match the number range from 01 to 09.
\b(0[1-9]|[12][0-9]|3[01])\b

Display MySQL database table data in VB 2010 textboxes

I was able to display data from my MySQL table using this code:
datardr = cmd.ExecuteReader
If datardr.HasRows Then
datardr.Read()
tb_lname.Text = datardr("SURNAME")
tb_fname.Text = datardr("GIVEN")
tb_mname.Text = datardr("MID")
tb_mi.Text = datardr("MIDDLE")
tb_app.Text = datardr("APPELLATION")
tb_prefix.Text = datardr("PREFIX")
tb_sex.Text = datardr("SEX")
tb_status.Text = datardr("STATUS")
End If
However, I noticed that it's not displaying all data coming from these fields. I can only view the SURNAME, GIVEN, MID and MIDDLE but the others are not displayed.. I have double checked my database fields and I'm sure that they're the same and without special characters or whitespaces.
Please help. Thanks!
Here is the exact code that I have => VB2010 and MySQL Code
Alright, here's another answer for you.
I think it's because of your SQL statement in line 21.
I assume you are selecting ONE record (am I right?), so that you can insert the resultant fields into the text boxes. And, you order the result with SURNAME.
Did you double check whether there are already data inside the masterlist table? Especially check, if you already entered the data in every field in every row.
In line 30, you called datardr.Read() method, so the DataReader object datardr will read the first record line it encountered in the result of the sql statement.I think only the four fields of the first record, SURNAME, GIVEN, MID and MIDDLE has data values, and any other fields contain null values. So, you only got these FOUR values appeared inside the text boxes, and any other fields appeared to be blank.
I THINK IT MIGHT BE THE MAIN PROBLEM. Just check whether the data you wanted to be appeared already existed in the database table. OK!
And another suggestion. Don't you think you might need WHERE clause in your SQL statement? Well, you want to display only one record, don't you?
WISH YOU BEST LUCK!!! :-)
I think you better check the sql statement that passed into the command object, cmd.
Maybe you didn't select the entire record with select *.
And, one more recommendation.
If datardr is the DataReader, I highly recommend you NOT to use it. It cause much problems than it serves.
The more flexible approach is to use just the DataTable.
The command object has ExecuteNonQuery method that returns the DataTable object.
It is more flexible and much more easier to use than DataReader. Trust Me...! ;-)