SPLIT() then JOIN() and populate column with ARRAYFORMULA() - email

I am trying to Split email addresses in column E2:E on the "dot" operator and then Join the names back into a single cell. I have written the below formula enclosed with ARRAYFORMULA() to populate the cells in Column A. But i keep getting the following error:
JOIN range must be a single row or a single column.
=ARRAYFORMULA( IF( E2:E = "", "", JOIN( " ", SPLIT( SUBSTITUTE( FILTER( E2:E, LEN( E2:E ) > 0 ), "#abc.com", "", 1 ), ".") ) ) )
Is there a workaround solution?

I think i found the answer:
=ARRAYFORMULA(IF(E2:E="","",TRANSPOSE(QUERY(TRANSPOSE(SPLIT(SUBSTITUTE(FILTER(E2:E,LEN(E2:E)>0),"#ABC.COM","",1),".")),,50000))))

Related

Snowflake MERGE with columns that have spaces in their names

I'm using Snowflake and have a table that has columns with spaces in their names. The code to create the table is:
create or replace MYTABLE (
"string 1" VARCHAR,
"number 1" NUMBER(38,0)
);
I want to now MERGE some data into the table using the following code:
merge into mytable using (
select * from
(
values('a', 4),('b', 5)
)
) as T ("string 1", "number 1") on FALSE
when not matched then
insert
("string 1", "number 1")
values
('string 1', 'number 1');
When I run the above, I get the following error:
Numeric value 'number 1' is not recognized
I've tried all manners of wrapping the column names in single quotes, double quotes, and $$ all to no avail. Suggestions?
Column could be referenced as T."""string 1""":
merge into mytable
using (
select * from
(
values('a', 4),('b', 5)
)
) as T ("string 1", "number 1") on FALSE
when not matched then
insert
("string 1", "number 1")
values
(T."""string 1""", T."""number 1""");
Output:
Rationale:
select *
from (values('a', 4),('b', 5)
) as T ("string 1", "number 1");
DESCRIBE RESULT LAST_QUERY_ID();
-- name
-- "string 1"
-- "number 1"
" is part of the column name "string 1" therefore when referencing """string 1"""

FMP 14 - Auto Populate a Field based on a calculation

I am using FMP 14 and would like to auto-populate field A based on the following calulation:
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v1" ; "1st" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v2" ; "2nd" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v3" ; "3rd" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v4" ; "4th" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v5" ; "5th" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v6" ; "6th" )
The above code is supposed to auto-populate the value 1st, 2nd, 3rd ... in field A depending on the name of the object the Get (ActiveLayoutObjectName) function returns. I have named each of my tabs, but the calculation is only returning 0.
Any help would be appreciated.
thanks.
The way your calculation is written makes very little sense. Each one of the If() statements returns a result of either "1st", "2nd", etc. or nothing (an empty string). You are then applying or to all these results. Since only of them can be true, your calculation is essentially doing something like:
"" or "2nd" or "" or "" or "" or ""
which happens to return 1 (true), but has no useful meaning.
You should be using the Case() function here:
Case (
Get ( ActiveLayoutObjectName ) = "tab_Visits_v1" ; "1st" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v2" ; "2nd" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v3" ; "3rd" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v4" ; "4th" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v5" ; "5th" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v6" ; "6th"
)
Note also that a calculation field may not always refresh itself as a result of user switching a tab. This refers to an unstored calculation field; if you are trying to use this as the formula to be auto-entered into a "regular' (e.g. Text) field, it will never update.
Added:
Here is our situation. We see a patient a maximum of 6 times. We have
a tab for each one of those 6 visits.
I would suggest you use a portal to a related table of Visits instead of a tab control. A tab control is designed to display fixed components of user interface - not dynamic data. And certainly not data split into separate records. You should have only one unique record for each patient - and as many records for each patient's visits as may be necessary (potentially unlimited).
If you like, you can use the portal rows as buttons to select a specific visit to view in more detail (similar to a tab control, except that the portal shows the "tabs" as vertical rows). A one-row portal to the same Visits table, filtered by the user selection, would work very well for this purpose, I believe.
With 1. .... it would be easy:
Right (Get ( ActiveLayoutObjectName ) ; 1) & "."
Thanks for pointing out, that my first version does not work.

How can I combine these two statements?

I'm currently trying to insert data into a database from a text boxes, $enter / $enter2 being where the text is being written.
The database consists of three columns ID, name and nametwo
ID is auto incrementing and works fine
Both statements work fine on their own, but because they are being issued separately the first leaves nametwo blank and the second leaves name blank.
I've tried combining both but haven't had much luck, hope someone can help.
$dbh->do("INSERT INTO $table(name) VALUES ('".$enter."')");
$dbh->do("INSERT INTO $table(nametwo) VALUES ('".$enter2."')");
To paraphrase what others have said:
my $sth = $dbh->prepare("INSERT INTO $table(name,nametwo) values (?,?)");
$sth->execute($enter, $enter2);
So you don't have to worry about quoting.
You should read database manual.
The query should be:
$dbh->do("INSERT INTO $table(name,nametwo) VALUES ('".$enter."', '".$enter2."')");
The SQL syntax is
INSERT INTO MyTable (
name_one,
name_two
) VALUES (
"value_one",
"value_two"
)
Your way of generating SQL statements is very fragile. For example, it will fail if the table name is Values or the value is Jester's.
Solution 1:
$dbh->do("
INSERT INTO ".$dbh->quote_identifier($table_name)."
name_one,
name_two
) VALUES (
".$dbh->quote($value_one).",
".$dbh->quote($value_two)."
)
");
Solution 2: Placeholders
$dbh->do(
" INSERT INTO ".$dbh->quote_identifier($table_name)."
name_one,
name_two
) VALUES (
?, ?
)
",
undef,
$value_one,
$value_two,
);

how to replace comma in List of string in Jasper report

I have create one report with list of the string. The string got value parameter TO.REFOS_STATUS_CODE in ('10','ZZ','11','12','13'). i want to replace "," with ".". i have try the solution with my expression but it does'nt work.
The parameter expression is $P{refos_status}.equalsIgnoreCase("0") ?" ": " TO.REFOS_STATUS_CODE IN ( " +$P{refos_status}.replace( ',', '.' )+ ")".
Anyone know how to do that?
This is my query:
SELECT
TO.REFOS_STATUS_DESC_RPT ,
SUM(US.ENFUS_TOTAL_OFF_ACT) TOTAL
FROM TENF_RPT_UNSETTLE_SUMMACT US
INNER JOIN TREF_BRANCH B ON B.REFBR_BRANCH_ID = US.ENFUS_BRANCH
INNER JOIN TREF_STATE ST ON B.REFBR_STATE_CODE = ST.REFST_STATE_CODE
INNER JOIN TREF_OFFENCE_STATUS TO ON US.ENFUS_OFF_ACT =TO.REFOS_STATUS_CODE
WHERE
$P!{refos_status_1}
GROUP BY
TO.REFOS_STATUS_CODE,
TO.REFOS_STATUS_DESC_RPT
ORDER BY
TO.REFOS_STATUS_CODE,
TO.REFOS_STATUS_DESC_RPT

Report Builder .rdl Check Array Key Exists

I am making a report and I need to split a coma separated string into three columns of a table.
string = 'some text, some text, some text'
But the sting doesn't always have two coma's i.e.
string = 'some text, some text'
so when i try to get the value for the third column
=Split(Fields!GLDescription.Value, ", ").GetValue(2)
This code can result in a "#Error" message in the column. I tried to solve this by checking the length like so
=IIF(Split(Fields!GLDescription.Value, ", ").Length >= 3, Split(Fields!GLDescription.Value, ", ").GetValue(2), "")
But it still resulted in the same error. Is there anyway to check if an array key exists?
The issue, as you've seen, is that SSRS IIf expressions aren't good at short circuiting. I can think of a workaround that will work for 2 and 3 column fields.
Try an expression like:
=IIf(
Split(Fields!GLDescription.Value, ", ").Length = 3
, Mid(
Fields!GLDescription.Value
, InStrRev(Fields!GLDescription.Value, ", ") + 2
, Len(Fields!GLDescription.Value) - InStrRev(Fields!GLDescription.Value, ", ") + 2
)
, "No val 3"
)
With dataset:
Gives result:
It's not bulletproof for all possible situations, but might be enough for your data.