How do I zero pad in hql - hql

I have the following query
final StringBuffer hql = new StringBuffer()
.append("select p.productDetails from Product as p WHERE lower(p.sku || ' ' || p.productDetails.name) like lower(:filter)");
The user should be able to type in a filter on a web form that is sent to the back end. The filter may be part of the sku or the name. the sku is stored as an Integer in the database, and therefore leading zeros don't exist, but the user may type in the leading zeros. Currently when the user types 00185 it will find 200185, but not 001852.
How do I zero pad the "p.sku"?

Related

Netsuite Saved Search Criteria Formula with 2 fields

I'm trying to do a saved search filter with a formula (text) criteria based on 2 fields, an item field and custom field.
How can I write the correct formula text in criteria? to create the correct filter to find a specific word in this 2 fields
Eg: I have items called with special nomenclature (SERIAL NUMBER_CODE) and also I created a custom field into journal entry line called (SERIAL NUMBER_CODE_RELATED not an item) now I need to find in the saved search all type of transaction with a specific SERIAL NUMBER_CODE + journal entry that have that SERIAL CODE as well into the line, also add a filter that a user can type the SERIAL CODE and bring transactions + journals.
I used this formula (text) in criteria:
CASE WHEN {custom_field} = 'SERIALCODE' OR {item} = 'SERIALCODE' THEN '1' ELSE '0' END
IS = space
Type = all kind of netsuite transaction
in available filter tap I added formula text show in filter region
the result doesn't bring me anything
Thank you
Try
formulatext NVL({custom_field},{item}) is %
Or
formulatext {custom_field}||' '||{item} contains space

Acrobat XI - Blanking a field if conditions are met

I have a form my drivers complete where part of the form is related to fueling. There is a possibility of 6 separate fuel stops. Each fuel stop line has input where gallons and cost are also included. By default the Cost and Gallons purchased cost is set to $0.00.
My reason for asking assistance:
Occasionally the drivers will inadvertently clicks into one of the date fields on a fueling line and the date will auto populate with the then current date (which can be changed). Then the rest of that line remains all zeros.
I am trying to figure out a validation script that will put the date field back to NULL preferably (or blank) if the Fuel Purchase Cost is at $0.00 as well as the DEF Purchase Cost is also $0.00. BOTH of these items need to be true. Additionally I am not sure how to keep the user inputted DATE if FUEL_PURCH_STOP_1 is >0 AND DEF_PURCH_STOP_1 >0.
NOTE: Fueling will always span 2-3 days.
My end goal is... If a driver clicks in the date field inadvertently, the current date is auto populated. Then if there is a "0" in the both the FUEL_PURCH_STOP_1 AND DEF_PURCH_STOP_1 fields then remove the date from that line. If either one or both of the two fields have a value >0 then I want to keep the user inputted date in the field.
I tried:
var v1 = +getField("FUEL_PURCH_STOP_1").value;
var v2 = +getField("DEF_PURCH_STOP_1").value;
// Set this field's value
if v1 >0 andalso v2 >0) {
event.valueAsString === "WHAT GOES HERE??";
} else {
event.valueAsString === "";
}
Put the following script into the custom calculation for your date field.
var v1 = this.getField("FUEL_PURCH_STOP_1").value;
var v2 = this.getField("DEF_PURCH_STOP_1").value;
// Set this field's value
if (v1 == 0 && v2 == 0) {
event.target.value = "";
}
Using this script, the date entry will only get modified if both of the other fields are zero. It's left as is when the criteria is not met so you don't actually need the "WHAT GOES HERE??" value.

Is there an ISNUMBER() or ISTEXT() equivalent for Power Query?

I have a column with mixed types of Number and Text and am trying to separate them into different columns using an if ... then ... else conditional. Is there an ISNUMBER() or ISTEXT equivalent for power query?
Here is how to check type in Excel Powerquery
IsNumber
=Value.Is(Value.FromText([ColumnOfMixedValues]), type number)
IsText
=Value.Is(Value.FromText([ColumnOfMixedValues]), type text)
hope it helps!
That depends a bit on the nature of the data and how it is originally encoded. Power Query is more strongly typed than Excel.
For example:
Source = Table.FromRecords({[A=1],[A="1"],[A="a"]})
Creates a table with three rows. The first row's data type is number. The second and third rows are both text. But the second row's text could be interpreted as a number.
The following is a query that creates two new columns showing if each row is a text or number type. The first column checks the data type. The second column attempts to guess the data type based on the value. The guessing code assumes everything that isn't a number is text.
Example Code
Edit: Borrowing from #AlejandroLopez-Lago-MSFT's comment for the interpreted type.
let
Source = Table.FromRecords({[A=1],[A="1"],[A="a"]}),
#"Added Custom" = Table.AddColumn(Source, "Type", each
let
TypeLookup = (inputType as type) as text =>
Table.FromRecords(
{
[Type=type text, Value="Text"],
[Type=type number, Value="Number"]
}
){[Type=inputType]}[Value]
in
TypeLookup(Value.Type([A]))
),
#"Added Custom 2" = Table.AddColumn(#"Added Custom", "Interpreted Type", each
let
result = try Number.From([A]) otherwise "Text",
resultType = if result = "Text" then "Text" else "Number"
in
resultType
)
in
#"Added Custom 2"
Sample output
Put it in logical test format
Value.Type([Column1]) = type number
Value.Type([Column1]) = type text
The function Value.Type returns a type, so by putting it in equation thus return a true / false.
Also, equivalently,
Value.Type([Column1]) = Date.Type
Value.Type([Column1]) = Text.Type
HTH
ISTEXT() doesn't exist in any language I've worked with - typically any numeric or date value can be converted to text so what would be a false result?
For ISNUMBER, I would solve this without any code by changing the Data Type to a number type e.g. Whole Number. Any rows that don't convert will show Error - you can then apply Replace Errors or Remove Errors to handle them.
Use Duplicate Column first if you don't want to disturb the original column.
I agree with Mike Honey.
I have a SKU code that is a mix of Char and Num.
Normally the last 8 Char are Numbers but in some weird circumstances the SKU is repeated with an additional letter but given the same EAN which causes chaos.
by creating a new temp column using Text.End(SKU, 1) I get only the last character. I then convert that column to Whole Number. Any Error rows are then removed to leave only the rows I need. I then delete the temp Column and am left with the Rows I need in the format I started with.

how to use COALESCE in oracle to combine data from two rows

I have the following query which is inside a loop and is breaking
SELECT COALESCE(v_user_grade || ', ', '') || user_grade
INTO v_user_grade
FROM EXPIRATION_HISTORY__2
WHERE hist_id = v_test;
So basically in each iteration of the loop we get a new value for v_test. In some cases this query would return multiple rows. that is when it is breaking.
What I want is:
Data in EXPIRATION_HISTORY__2:
hist_id user_grade
301 ADMIN
302 ADMIN
302 USER
so now based on the above data. ...in the end of the iteration where v_test = 302. I would want v_user_grade to contain (ADMIN, USER)
I think the following link describes exactly that what you want:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
String Aggregation Techniques
On occasion it is necessary to aggregate
data from a number of rows into a
single row, giving a list of data
associated with a specific value.
I'm not an Oracle expert; but there are multiple solutions, depending on your DB enviroment.

PL/SQL: UPDATE inside CURSOR, but some data is NULL

I'm still learning some of the PL/SQL differences, so this may be an easy question, but... here goes.
I have a cursor which grabs a bunch of records with multiple fields. I then run two separate SELECT statements in a LOOP from the cursor results to grab some distances and calculate those distances. These work perfectly.
When I go to update the table with the new values, my problem is that there are four pieces of specific criteria.
update work
set kilometers = calc_kilo,
kilo_test = test_kilo
where lc = rm.lc
AND ld = rm.ld
AND le = rm.le
AND lf = rm.lf
AND code = rm.code
AND lcode = rm.lcode
and user_id = username;
My problem is that this rarely updating because rm.lf and rm.le have NULL values in the database. How can I combat this, and create the correct update.
If I'm understanding you correctly, you want to match lf with rm.lf, including when they're both null? If that's what you want, then this will do it:
...
AND (lf = rm.lf
OR (lf IS NULL AND rm.lf IS NULL)
)
...
It's comparing the values of lf and rm.lf, which will return false if either is null, so the OR condition returns true if they're both null.
I have a cursor which grabs a bunch of records with multiple fields. I then run two separate SELECT statements in a LOOP from the cursor results to grab some distances and calculate those distances. These work perfectly.
When I go to update the table with the new values, my problem is that there are four pieces of specific criteria.
The first thing I'd look at is not using a cursor to read data, then make calculations, then perform updates. In 99% of cases it's faster and easier to just run updates that do all of this in a single step
update work
set kilometers = calc_kilo,
kilo_test = test_kilo
where lc = rm.lc
AND ld = rm.ld
AND NVL(le,'x') = NVL(rm.le,'x')
AND NVL(lf,'x') = NVL(rm.lf,'x')
AND code = rm.code
AND lcode = rm.lcode
and user_id = username;

Resources