Using a case when result for comparison in another case when in NetSuite - search

I am trying to run an equation on a saved search in NetSuite that uses a formula, and a field.
I can run this and I get the correct value:
CASE WHEN {systemnotes.context}='UI' AND {systemnotes.field}='Date Closed' THEN {systemnotes.newvalue} END
And, this returns the correct value:
{startdate}
But, I can not figure out how to say that if the first case does not return a null value, and the second one is not null then give me the difference between the two. I was trying something like this (in many different variations:
CASE WHEN [(CASE WHEN {systemnotes.context}='UI' AND {systemnotes.field}='Date Closed' THEN {systemnotes.newvalue} END) IS NOT NULL AND {startdate} IS NOT NULL] THEN
{CASE WHEN {systemnotes.context}='UI' AND {systemnotes.field}='Date Closed' THEN {systemnotes.newvalue} END)-{startdate}
END
Every time I run it I get invalid expression. I've Googled around adn con not seem to find anything that discusses this type of operation, though.

The formula below worked for me. I couldn't tell what recordtype you were running against so I just added a custom date field to the case record called Test Date Field. Just replace the field name with yours and it should work.
The key is that {systemnotes.newvalue} returns text so you need to wrap that result in TO_DATE() to convert it. Then you can subtract {startdate} from it.
Your column type should be Formula(numeric).
case when
(CASE WHEN {systemnotes.context}='UI' AND {systemnotes.field}='Test Date Field' THEN {systemnotes.newvalue} END is not null and {startdate} is not null)
then (TO_DATE(CASE WHEN {systemnotes.context}='UI' AND {systemnotes.field}='Test Date Field' THEN {systemnotes.newvalue} END) - {startdate}) END

Related

Trying to write a simple computed column expression (IF Statement)

I have a column in my table called "BanquetPrize" and another column called "PrizeWinner." If the "BanquetPrize" field is NOT NULL, I'd like the "PrizeWinner" field to auto-fill with "YES," and if it IS NULL, it should be "NO." (Persisted)
I'm really new to SQL and coming from DBF tables where the expression would have been:
IF(IsNotBlank(BanquetPrize), "YES", "NO")
But I can't figure out how to write it in SQL. What I've tried:
(IIF [BanquetPrize]isnotnull then 'YES' else 'NO' end)
-- and also --
(case when [BanquetPrize]isnotnull then 'YES' else 'NO' end)
Obviously the syntax was wrong with both of these, so I was hoping someone could educate me on the correct way to write it?
In SQL You want to use IS NULL as shown in the following code
CASE [BanquetPrize]
WHEN IS NULL THEN 'NO'
ELSE 'YES'
END
You can also do something like the following to give the return column a name, in this case I am giving it a name same as column which is BanquetPrize
CASE [BanquetPrize]
WHEN IS NULL THEN 'NO'
ELSE 'YES'
END AS 'BanquetPrize'
Additional Example when using CASE in ORDER BY Clause
SELECT CustomerName, City, Country
FROM Customers
ORDER BY
(CASE
WHEN City IS NULL THEN Country
ELSE City
END);
Read more about SQL CASE statement and using IS NULL here https://www.w3schools.com/sql/sql_case.asp
You can use CASE or IIF
CASE
SELECT BanquetPrize, CASE WHEN BanquetPrize IS NOT NULL THEN 'YES' ELSE 'NO' END as PrizeWinner
FROM t1;
IIF
SELECT BanquetPrize, IIF(BanquetPrize iS NOT NULL,'YES','NO') as PrizeWinner
FROM t1;
Demo

Combining two separate case statements in NetSuite Case Statements

I currently have two separate saved search columns for these two statements, and I'm hoping to combine them and list the data in just one column. I've tried OR AND, but the results then error out.
First Statement
Case when {item.custitem54} is null then {quantity} else null end
Second Statement
Case when {item.custitem54} = 'Yes' and {shipdate} between to_date('05/25/2020', 'MM/DD/YYYY') and to_date('12/25/2020', 'MM/DD/YYYY') then {quantity} else null end
You can have multiple WHEN in a case statement. The first matched WHEN determines the result unless it gets to the ELSE.
Case when {item.custitem54} = 'Yes'
and {shipdate} between date '2020-05-25' and date '2020-12-25' then {quantity}
when {item.custitem54} is null then {quantity}
else null
end

IF statement to determine date

I want to set an order completion date based on the words Standard or Rush.
Currently I have it set up where if a cell shows the word Standard, it will give me a date, but once I try to add Rush to that, it get errors
=IF(ISNUMBER(SEARCH("VF",B2)), IF(J2="Standard", WORKDAY(TODAY( )+2,1)), "")
I also tried this, but when I type Rush into J2, the result shows as just FALSE
=IF(ISNUMBER(SEARCH("VF",B2)), (IF(J2="Standard", WORKDAY(TODAY( )+2,1))), (IF(J2="Rush", WORKDAY(TODAY( )+1,1))))
The idea here is to make an order wanted date based on the Rush and Standard time frame.
You have embedded your new IF function inside of the wrong if.
This: (IF(J2="Standard", WORKDAY(TODAY( )+2,1))) is going to return a date or FALSE. You want to change that FALSE to return your next IF statement. Instead:
=IF(ISNUMBER(SEARCH("VF",B2)), IF(J2="Standard", WORKDAY(TODAY( )+2,1), IF(J2="Rush", WORKDAY(TODAY( )+1,1))), "")
You return nothing "" in the case that your ISNUMBER() fails still.

OR Formula in Word document not returning a value

I am working on a document where I need to be able to test multiple options in an if statement to see if one of them are true to decide if a paragraph displays on the document. I have been trying to figure out why my OR formula is not returning a value for me to test and I am not sure why it is not showing anything when it is updating.
I have inserted a field and added a formula within that field that I am hoping will work with my If statement to show the proper paragraph contens.
When I use an Or statement, even one as simple as { OR(1=1) } and update and toggle the field I get no result. From what I have read I should get a 1 or a 0, but I don't seem to get either of these results. The line just ends up blank. When I test it with my If formula it always shows the false result, even when the Or contains a true result.
The formula I am currently working with is:
{ IF{ OR("$event.eventType.name}" = "Birthday", "$event.eventType.name}" =
"Conference" } "Yes" "No" }
If I update and toggle the Or field it shows blank, no result either true or false, and makes the If formula show as false event on results where it should show true. As I mentioned above I even tried setting it to 1=1 and still could not get it to show as true. Not sure if there is something I am missing in working with the formula.
Any suggestions would be appreciated.
It's not clear from your post what $event.eventType.name is. Presumably it's a field generated by an Addin. In that case, you should be able to use something like:
{IF{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0}# 0}> 0 "Yes" "No"}
or:
{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0} \# "'Yes',,'No'"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. If your fields are a kind of mergefield, you'll need to insert 'MERGEFIELD ' at the start of each one, thus:
{MERGEFIELD $event.eventType.name}

Cognos query calculation - how to obtain a null/blank value?

I have a query calculation that should throw me either a value (if conditions are met) or a blank/null value.
The code is in the following form:
if([attribute] > 3)
then ('value')
else ('')
At the moment the only way I could find to obtain the result is the use of '' (i.e. an empty character string), but this a value as well, so when I subsequently count the number of distinct values in another query I struggle to get the correct number (the empty string should be removed from the count, if found).
I can get the result with the following code:
if (attribute='') in ([first_query].[attribute]))
then (count(distinct(attribute)-1)
else (count(distinct(attribute))
How to avoid the double calculation in all later queries involving the count of attribute?
I use this Cognos function:
nullif(1, 1)
I found out that this can be managed using the case when function:
case
when ([attribute] > 3)
then ('value')
end
The difference is that case when doesn't need to have all the possible options for Handling data, and if it founds a case that is not in the list it just returns a blank cell.
Perfect for what I needed (and not as well documented on the web as the opposite case, i.e. dealing with null cases that should be zero).

Resources