Nesting 2 Case When Formulas - NetSuite Saved Search - case

I am needing to combine these two CASE WHEN statement for a netsuite saved search. How do I do this?
CASE WHEN {type}='bill' AND {vendeor.altname}='AMERICAN EXPRESS' THEN 'STEP 3 BILL' ELSE 'STEP 1 BILL' END
CASE WHEN {type}='bill payment' AND {vendeor.altname}='AMERICAN EXPRESS' THEN 'STEP 4 BILL PAYMENT' ELSE 'STEP 2 DUMMY PAYMENT' END

You're question is missing some logic but essentially a case statement can have multiple WHEN clauses so you're looking for something like:
CASE
WHEN xxx THEN 'STEP 1 BILL'
WHEN yyy THEN 'STEP 2 DUMMY PAYMENT'
WHEN {type}='bill' AND {vendor.altname}='AMERICAN EXPRESS' THEN 'STEP 3 BILL'
WHEN {type}='bill payment' AND {vendor.altname}='AMERICAN EXPRESS' THEN 'STEP 4 BILL PAYMENT'
ELSE 'unconfigured'
END
NOTE: I often write complex case statements in a blank page on a proper editor to make them clearer. If you do that be aware that when you paste it back into the formula field Netsuite has, in the past, stripped the line feeds but didn't replace them with spaces.

Related

How to get the comma separated values into rows like one below another oracle apex

I have a apex item with values like Value1,Value2,Value3, so on i need to show the values like below
Value 1
Value 2
Value 3
below is my select query, can anyone help here to show the comma seperated values as one below another
ex :: a,b,c,d
i need to see the output as
a
b
c
d
SELECT AD.EMAIL_ADDRESS recipient
FROM HES_EXTERNAL_ACCOUNTS EA,
HES_ADDRESSES AD
WHERE EA.ACCOUNT_CODE = 'AUTO';
The above query will result the email address like a,b,c,d i need to show in apex item as
a
b
c
d
While Chris Saxon's post describe many SQL scenarios, and a cool SQL macro, APEX provides a simple tool for splitting strings into rows:
select column_value from table(apex_string.split('a,b,c,d',','));
Result Sequence
----------------
a
b
c
d
That table() clause isn't required from a certain db version, perhaps 18c.
But your question isn't completely clear as to the output you need. On one hand it seems like you want to replace commas with spaces
replace('a,b,c,d', ',', ' ')
but then another moment you suggest one of top of the other
replace('a,b,c,d', ',', '<br>')
If displayed as a column in a report, this would need escaping turned off.
If that select returns a single row, then this is a possible solution:
CREATE TABLE emails (email_list) AS (
select 'mickey.mouse#disney.com, homer.simpson#acme.com'
from dual
);
Table EMAILS created.
select TRIM(regexp_substr (
email_list,
'[^,]+',
1,
level
)) email
from emails
connect by level <=
length ( trim ( both ',' from email_list ) ) -
length ( replace ( email_list, ',' ) ) + 1;
EMAIL
-----------------------------------------------
mickey.mouse#disney.com
homer.simpson#acme.com
But Chris has already done all the research and blogged about it here. That blog sums up most common cases and a solution in each of those cases.

Proper method of performing multiple inserts of textual data into text widget as step through sqlite results?

I'm attempting to extract multiple rows of textual data from SQLite and add tags to it to display in a Tk text widget.
If I were doing something similar in a browser, I would build the elements in a document fragment and then add the fragment to the DOM, as opposed to writing to the DOM multiple times. Is there an equivalent approach in Tk; or is it efficient to perform inserts repeatedly in the database results loop in Tcl that is equivalent to the sqlite3_step in the C API?
For example (where there may be up to a few hundred such rows returned by the query)
db1 eval {SELECT * FROM table ...} {
.widget insert end $column_1 "tag_1 tag_x"
.widget insert end $column_2 "tag_2 tag_y"
.widget insert end $column_3\n "tag_3 tag_x"
}
Or, should one attempt to use something like GROUP_CONCAT in the SQL to build a single statement to evaluate in Tcl?
Thank you.
A more specific example is below. The data for a single verse is made up of multiple rows in the database; and, most often, many verses will be extracted at once. I need to tag the strongs_no column such that it can be styled as a superscript.
If I just select the rows, then there will be many inserts; but, if I use group_concat in the SQL, then I don't know how to add the tags.
If that were possible, there'd still be an insert for every verse returned.
book_no chapter_no verse_no index_no strongs_no kjv_text
------- ---------- -------- -------- ---------- ----------------
1 1 1 1 H7225 In the beginning
1 1 1 2 H430 God
1 1 1 3 H1254 created
1 1 1 4 H853
1 1 1 5 H8064 the heaven
1 1 1 6 H853 and
1 1 1 7 H776 the earth.
select group_concat( kjv_text || strongs_no, ' ') as kjv
from blb_kjv_text
where book_no=1
and chapter_no=1
and verse_no=1
kjv
---------------------------------------------------------------------
In the beginningH7225 GodH430 createdH1254 H853 the heavenH8064 andH853 the earth.H776
If you want to apply different tags to each span of text, it's probably easiest to use many insert calls. Individually, they're not very expensive (the measuring and rendering are the costly bits, but they're postponed until the application is idle so you don't really see the costs in most applications). If you're not inserting at the end, set your own custom mark (with default rightward gravity) and do the inserts at that; it has fewest surprises.
I really wouldn't do the GROUP_CONCAT in SQL unless there's some other query-related reason for doing so, as Tcl's extremely good at text manipulation.

PL/SQL: Creating a Function: invalid identifier

I have an oracle 19c ee database build via their docker image on Oracles github (https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance). I am trying to follow their example as to how to create a function from here.
I have copied their example exactly. Setup table and data:
CREATE TABLE orders (
customer_id number(10),
order_total NUMBER(11,2)
);
INSERT INTO orders (customer_id, order_total) VALUES (1, 200.01)
The actual function:
CREATE FUNCTION get_bal(acc_no IN NUMBER)
RETURN NUMBER
IS acc_bal NUMBER(11,2);
BEGIN
SELECT order_total
INTO acc_bal
FROM orders
WHERE customer_id = acc_no;
RETURN(acc_bal);
END;
However I keep running into this error when I try and create the function
Query 2 ERROR: ORA-06550: line 5, column 27:
PL/SQL: ORA-00904: "ACC_NO": invalid identifier
ORA-06550: line 2, column 7:
PL/SQL: SQL Statement ignored
ORA-06550: line 6, column 7:
PLS-00372: In a procedure, RETURN statement cannot contain an expression
ORA-06550: line 6, column 7:
PL/SQL: Statement ignored
What am I doing wrong?
The example works for me. You must have mistyped something. Are you sure your function is exactly the same as the one in the manual?
ORA-00904: "ACC_NO": invalid identifier
suggests the declaration acc_bal NUMBER(11,2); is missing or different.
PLS-00372: In a procedure, RETURN statement cannot contain an expression
indicates that your code is a procedure, not a function.
SQL> CREATE TABLE orders (
2 customer_id number(10),
3 order_total NUMBER(11,2)
4 );
Table created
SQL> INSERT INTO orders (customer_id, order_total) VALUES (1, 200.01);
1 row inserted
SQL> CREATE FUNCTION get_bal(acc_no IN NUMBER)
2 RETURN NUMBER
3 IS acc_bal NUMBER(11,2);
4 BEGIN
5 SELECT order_total
6 INTO acc_bal
7 FROM orders
8 WHERE customer_id = acc_no;
9 RETURN(acc_bal);
10 END;
11 /
Function created
SQL> select get_bal(1) from dual;
GET_BAL(1)
----------
200.01
As an aside, while I'm a big fan of the Oracle documentation in general, and this example does neatly illustrate how to create a PL/SQL function, I think it could be improved:
For readability, it's better to give each declaration its own line, so line 3 would be better split into two with acc_bal NUMBER(11,2); on its own line.
The IS and AS keywords are interchangeable here, but surely create ... as (similar to what you might use to create a table or a view) reads better than create ... is.
Understandably, the author didn't want to complicate the example by introducing %type before it had been explained, but a more advanced version would use acc_bal orders.order_total%type; to make acc_bal inherit its datatype from the table column rather than hard-coding it. This goes for all three values used in the function.
The parameter and variable names are OK - they are at least clear - but there is a danger when using the same naming pattern for parameters and variables as for table columns. One day you will type WHERE c.customer_id = customer_id and wonder why you're getting more rows back than you expected. Again it's understandable that the author didn't want to get into that whole discussion in the first example, but it's something to think about. You might use get_bal.acc_no within the function, or use camelCase for parameters and variables, or prefix them with p_ for 'parameter' etc.
A basic rule of layout is that opening and closing keywords such as if/else and begin/end should be left-aligned. The END at line 10 is misaligned under its opening BEGIN. I suppose indenting the entire thing after the first line is a valid personal layout choice, but to me it doesn't add anything.
It's a good idea to leave blank lines around each SQL statement, to avoid a solid wall of text. Personally, I'd prefer a blank line before the RETURN at line 9.
A RETURN clause doesn't require any brackets. The compiler is ignoring the redundant brackets at line 9. I'd lose them.
It's good practice (though optional) to include the procedure/function name in the closing END, so line 10 would become END get_bal;
The COBOL-style uppercase habit is widespread in the industry, but there is no need for it. (PL/SQL's syntax is famously based on Ada, though some also point to ALGOL and PL/1 - nobody ever wrote those in uppercase.) I would improve readability by lowercasing the whole thing.
With these changes, I get this:
create or replace function get_bal
( inAccNo in orders.customer_id%type )
return orders.order_total%type
as
accBal orders.order_total%type;
begin
select order_total into accBal
from orders
where customer_id = inAccNo;
return accBal;
end;

Line Breaks in MySQL Column

I have a mySQL column called description and I have several sentences in this column. For example: "John ran down a hill. He was tired. John went to get water." I would like a line break after each sentence so that it outputs like:
John went to get water.
He was tired.
John went to get water.
I'm using a SQLite DB Browser (http://sqlitebrowser.org/). I thought I could do line breaks with: "John ran down a hill. \n" but unfortunately it outputs the \n as well as the "". Can anyone help me with these line breaks? Thanks!
SQLite doesn't have string escaping logics. You have to concatenate the newline char using another way, like the char(10) function or typing it in exadecimal: x'0a'. Remember that the character 10 is the newLine for windows architectures.
Just use a query like this (to update all the rows):
update tabel_name set "description" =
replace("description", '.', '.' || x'0a')
If you want to edit a specific row add a WHERE clause:
update tabel_name set "description" =
replace("description", '.', '.' || x'0a')
WHERE "rowid" = 1
The || is the concatenation operator in SQLite.

xquery- how to put a 'range' condition on some nodes' immediately previous and next sibling nodes

Kindly take a look at the sample below--
<div class="patent_bibdata">
<b> First list</b>
Name #1
Name #2
<b> Second list</b>
Name #2_1
Name #2_2
</div>
Now, I want to extract the links after the 'b' element that has text "First List"-- however, I dont want the links after the 'b' element that has text "Second list"-- and the number of links after "First List" is not known to me.
What I thought of, is something like this--
....XQuery code defining the document as variable named "doc"
let $list:= $doc/div[ #class="patent_bibdata"]/b[. = 'First list']/following-sibling::text() -- but this should get everything after 'First list'-- including 'Second List' and 'Name #2_1' and 'Name #2_2'
Now, only the text in the 2 'b' tags-- (i.e. 'Name #1' and 'Name #2' in our example) are known to me-- so I think I have to somehow put conditions and retrieve the links (that I need), putting conditions on the immediate-predecessor-sibling and immediate-successor-sibling of those links--- what are the commands to put those conditions(if I am right so far)? And if I am not right, then how do I go about getting that set of links?
This works:
$doc/div[ #class="patent_bibdata"]/b[. = ' First list']/following-sibling::a[not(preceding-sibling::b[. = ' Second list'])]
Considering the amount of rather basic questions you asked today about XQuery it might be advisable to get a fundamental understanding about XQuery first. There are some very good books out there, I especially like the one from Priscilla Walmsley.

Resources