Netsuite Formula - "blank" or "null" field - case

I'm trying to use a formula to get a field populated with the word "false" in NetSuite, but currently when I use this I get nothing showing up. If I modify it slightly to say "null" or "blank" or leave it as just a space, it returns an error.
The code I'm using is
CASE WHEN {custitem_upc_number} = 'null' THEN 'FALSE' END

Try
CASE WHEN {custitem_upc_number} is NULL THEN 'FALSE' END
Also, for NetSuite Null check related formulas - give NVL and NVL2 a try
Syntax :
NVL({expression1}, {expression2})
NVL2({expression1}, {expression2}, {expression3})

Related

What's the meaning of "WHEN ? THEN"?

While reading some source code, I just stumbled upon the following piece of code in Progress:
WHEN ? THEN
...
In other languages, I've seen code like IF TRUE THEN ... (this code is always to be run) or IF FALSE THEN ... (this code is never to be run).
As ? means "nothing" in Progress, does this piece of code mean the same as IF FALSE THEN ...?
If that's used in a CASE statement, it compares the value used in the CASE block to the unknown value. That's similar to a switch statement in C-like languages.
CASE lOk:
WHEN TRUE THEN ...
WHEN FALSE THEN ...
WHEN ? THEN ...
END CASE .
In the expression
WHEN value[ OR WHEN value] . . . THEN
Each value is an expression that evaluates to a possible value for expression. If value matches the current value of expression, then the associated block or statement executes. The question now is, how to evaluate to an unknown or null value. This is done with the "?" character. For example:
IF myVariable = ? THEN DISPLAY "This value is unknown".
If instead you need to evaluate a comparison to an actual question mark character, all you need to do is enclose the question mark in single or double quotes.
IF myVariable = '?' THEN DISPLAY "This is a question mark".
IF myVariable = "?" THEN DISPLAY "This is a question mark".
For future reference, Progress Knowledgebase is a good place to get information.

Displaying the same value in SQL case statement

This might be a simple question but I am unable to find a solution for this, I have a SQL case statement of some form, for example:
CASE
WHEN table_1.col_1 IS NULL THEN 'NULL'
ELSE table_1.col_1
END as 'col_1'
col_1 is of TEXT data type. What I am trying to achieve is that I want NULL to be written wherever the value is NULL and then I want the original value to be displayed if it is not NULL.
I checked the rest of the query it is fine. Making the ELSE statement to 'table_1.col_1' results in all the NOT NULL values as 'table_1.col_1'.
Making the ELSE statement to 'table_1.col_1' results in all the NOT
NULL values as 'table_1.col_1'
Don't use single quotes because you get a string literal 'table_1.col_1' and not the value of the column table_1.col_1.
In the CASE expression that you posted though there are not single quotes around table_1.col_1 so it should work fine, but this logic can be expressed with COALESCE() like this:
COALESCE(table_1.col_1, 'NULL') AS col_1
Also don't use single quotes for aliases. If needed use backticks or square brackets.

How to check if decimal is valid value in Teradata

How to check if the given decimal is valid. I usually do a case statement like below to check if column is invalid or NULL then set it to 0 else take it as it is:
case when decimal_column is NULL or decimal_column NOT BETWEEN -999999999999 AND 999999999999 then 0 else decimal_column end
Can anyone please let me know if the above query looks correct
Thanks
In Teradata 14.10 or greater, the TO_NUMBER() function can be used.
SELECT TO_NUMBER({decimal column})
FROM {table};
If the conversion to number failed, TO_NUMBER() returns NULL. See the SQL Functions,Operators, Expressions and Predicates manual for more details.
You can also use trycast. Something like ..:
trycast(trim(col1)) as DECIMAL (XX,Y))
From TD-Doku: TRYCAST takes a string and tries to cast it to a data type specified after the AS keyword (similar to CAST). If the conversion fails, TRYCAST returns a NULL instead of failing.

ORM expr evaluate empty string

I have been using and still learning query expr(). I have a complex query where I cannot use if first to check if a parameter is '' - empty string.
I have to check it inside andX with nested orX using something like:
->andWhere($expr->orX($expr->eq(':sid', ''), $expr->neq('s.id', ':sid')))
Note: I know this line can be done by using if check first, I am using it just for an example, I got error says:
Error: Expected Literal, got ' OR '
I really need to compare empty string inside expr(), how?
Because '' is not an empty string. It's nothing and so it evaluates to nothing in DQL/SQL. Normally doctrine expects an named parameter. Either you create one to get quoted empty string or supply an empty string quoted by yourself.
Named parameter:
$qb->expr->eq('foo', ':foo');
$qb->expr->setParameter('foo', '');
quoted by yourself:
$qb->expr->eq('foo', "''");

How to use MariaDB's REGEXP_REPLACE?

I have read the docs for MariaDB's REGEX_REPLACE but cannot get my query to work. I am storing links in a column, link and want to change the end of the link:
From www.example.com/<code> to www.example.com/#/results/<code> where <code> is some hexidecimal hash, e.g. 55770abb384c06ee00e0c579. What I am trying is:
SELECT REGEX_REPLACE("link", "www\\.example\\.com\\/(.*)", "www\\.example\\.com\\/#\\/results\\/\\1");
The result is:
Showing rows 0 - 0.
I wasn't able to figure out what the first argument was--the documentation says "subject". Turns out it's just the column name. So this works:
UPDATE my_table
SET my_link = REGEXP_REPLACE(
my_link,
"http:\\/\\/www\\.example\\.com\\/(.*)",
"http:\\/\\/www\\.example\\.com\\/#\\/results\\/\\1")
WHERE my_link IS NOT NULL

Resources