Handling null values in informatica flat files - informatica

Hi guys My code looks like
iif(not isnull(ltrim(rtrim(a))) or not is_spaces(ltrim(rtrim(a))) or ltrim(rtrim(a))!='' or length(ltrim(rtrim(a)))!=0 or ltrim(rtrim(a))!=null or ltrim(rtrim(a))!='NULL'and not isnull(ltrim(rtrim(b))) or not is_spaces(ltrim(rtrim(b))) or ltrim(rtrim(b))!='' or length(ltrim(rtrim(b)))!=0 or ltrim(rtrim(b))!=null or ltrim(rtrim(b))!='NULL',null,ltrim(rtrim(a))).
If both a and b are not null then i have to make a as null else pass the value of a as it is. But my logic is not working fine and I've checked with session logs by giving verbose data for expression transformation still my value of b which is [NULL] coming in session logs has been considered as not null . Can you please help me guys for giving exact statements to identify the null values properly.
I've tried with is_spaces, empty strings.length!=0 options. But still null values are considered as an actual values which is wrong.

I think you need to group the conditions for a and b as shown below
IIF
(
(
NOT ISNULL(LTRIM(RTRIM(a)))
OR NOT IS_SPACES(LTRIM(RTRIM(a)))
OR LTRIM(RTRIM(a)) != ''
OR LENGTH(LTRIM(RTRIM(a))) != 0
OR LTRIM(RTRIM(a)) != NULL
OR LTRIM(RTRIM(a)) != 'NULL'
)
AND
(
NOT ISNULL(LTRIM(RTRIM(b)))
OR NOT IS_SPACES(LTRIM(RTRIM(b)))
OR LTRIM(RTRIM(b)) != ''
OR LENGTH(LTRIM(RTRIM(b))) != 0
OR LTRIM(RTRIM(b)) != null
OR LTRIM(RTRIM(b)) != 'NULL'
)
,NULL
,LTRIM(RTRIM(a))
)
Hope this helps.
NOTE: I have not optimized your checks for checking null conditions.

Related

How to transfer data with multiple conditions with pgsql?

I would like to create a trigger with I can check the uploaded data and I can insert into another table as well. In the initial table (capture) I have 15 columns, but I would like to transfer only 5 columns (ring_number, code, year, date, species, location) to another table (ring).
The ring table is a background table in which I am collecting the combinations of ring_number and code, more specifically one ring_number could be paired only with one code. There is one exception, when the code include "X", than it can be changed later, and in this case this code can be paired with more ring_number, and if originally belongs to the ring_number a code with "X" it can be changed later.
In the capture table, could be possible to upload the same combination of code and ring_number multiple times with a condition of a third column. But still the ring_number can be paired only with one code, with exceptions of codes included "X". The name of the conditional column is recapture. If recapture (boolean column type) is "true", then you can upload the combination of code and ring_number again. If it is "empty" or "no" you can upload only new combinations of code and ring_number. If somebody uploads old combinations then the following error message has to raise: this combination already exists, please check your data and if it is a recapture, then set the recapture column to yes.
Additionally: ring_number is a not null column, but code can be empty. And different ring_number can be paired with empty code than later can be paired with actual value.
I have several problems with my code:
1: I would like to define the exception to X with regex, and the X can be anywhere in the code. But can not manage the regex in a good way. It does just not work.
2: I write conditional checkpoint with recapture column and if I have an old combination this is work on the right way and say please set the recapture column to yes. But! If I set the recapture column to yes I get the same error message.
Could you help to solve these issues?
Here is my code:
Declare
a integer := 0;
b integer := 0;
c integer := 0;
d integer := 0;
Begin
IF new.code <> '' THEN
--Az 'a' means whether the given ring_number already exist in the database with a code, which is not empty
SELECT INTO a COUNT(*) FROM plover_captures PC WHERE PC.ring_number = new.ring_number AND PC.code <> new.code AND PC.code <> '' AND PC.code ~ '[X]{2}[\.]{1}[X]{2}[|]{1}[X]{2}[\.]{1}[X]{2}';
--Az 'b' means the given code already exist in the database with a ring_number
SELECT INTO b COUNT(*) FROM plover_captures PC WHERE PC.ring_number <> new.ring_number AND PC.code = new.code AND PC.code ~ '[X]{2}[\.]{1}[X]{2}[|]{1}[X]{2}[\.]{1}[X]{2}';
--Az 'c' how much times exist the given ring_number with the given code in the database
SELECT INTO c COUNT(*) FROM plover_captures PC WHERE PC.ring_number = new.ring_number AND PC.code = new.code AND PC.code ~ '[X]{2}[\.]{1}[X]{2}[|]{1}[X]{2}[\.]{1}[X]{2}';
--Az 'd' means the given combination already exist in ring table or not
SELECT INTO d COUNT(*) FROM plover_rings PC WHERE PC.ring_number = new.ring_number AND PC.code = new.code;
IF a > 0 THEN
raise exception 'This ring_number is already paired with another code before. %', new.ring_number;
END IF;
IF b > 0 THEN
raise exception 'This code is already paired with another ring_number before. %', new.code;
END IF;
IF c > 0 AND (new.rettrap IS null OR new.rettrap IS false) THEN
raise exception 'This ring_number and code pair is already in the database. So it is a rettrap but the rettrap attribute set to false or null. %, %, %', new.ring_number, new.code, new.rettrap;
END IF;
IF c = 0 AND new.rettrap IS true THEN
raise exception 'The rettrap attribute set to true but this ring_number and code pair is not in this database yet. %, %, %', new.ring_number, new.code, new.rettrap;
END IF;
IF c = 0 AND d = 0 THEN
Insert into plover_rings values(new.ring_number,new.code,new.species,new.location,new.year, new.date);
END IF;
END IF;
Return new;
End

Power Query M - We cannot convert the value null to type Logical

In Power BI I have an M Query that tests for the value in a column equaling or not equaling to null.
When I add the statement for [Sale.Revenue] <> null I get an error however it works fine for the [UserRole.Name] = null it works fine. Tested just by removing the statement and adding it back.
We cannot convert the value null to type Logical.
This seems like it should work but just can't figure it out.
add_user_role_group = Table.AddColumn(
join_expand_sale,
"UserRole.Group1",
each (
if [UserRole.Name] = null and
[Sale.Revenue] <> null then
"Group1"
else if Text.Contains([UserRole.Name], "Manager") then
"Group2"
else
"Undefined"
)
)
I am sure it is something glaringly obvious :/ Thanks for your thoughts on this.
One of your rows has a null value for both UserRole.Name and Sale.Revenue. You need to check for that explicitly, and then add it to the "Undefined" group.
What happened is that the first condition fails because Sale.Revenue is null. The second condition calls Text.Contains, which returns null when [UserRole.Name] is null (Text.Contains returns a nullable logical value). null is not true or false, so you get the error.
After a such journey, finaly I found Text.Length !!
You can solve your problem like this:
if Text.Length([UserRole.Name]) = 0 and
Text.Length([Sale.Revenue]) > 0 then
I hope I have helped you.
Reference: Power Query M - Text.Length
Your issue is in the Text.Contains formula. You create an if statement that expects an expression that returns either true or false.
When the Text.Contains formula contains a null value, it returns 'null' as answer, and not true or false. You can adjust your code:
Text.Contains([UserRole.Name], "Manager")
To
Text.Contains([UserRole.Name]??"", "Manager")
The ?? is the COALESCE operator. In case it finds a null value, it now treats it as "". Instead of returning null it now returns true or false.
More on text functions in this article: https://gorilla.bi/power-query/text-functions/
Enjoy Power Query,
Rick

Get last element from arryalist using drools DRL file

I am trying the following code
rule "Last activity"
salience 1
when
$notification : NotificationVO()
lastActivityOffset:Integer()
from $notification.offsetChngesInterval.
get($notification.offsetChngesInterval.size()-1)
then
System.out.println("Hello--"+$notification.offsetChngesInterval.size());
end
It gives error java.lang.reflect.InvocationTargetException.
Can anyone let me know what is causing this problem on the line
$notification.offsetChngesInterval.
get($notification.offsetChngesInterval.size()-1)
It does not allow me to get the last element from the list
It is advisable to write
$notification : NotificationVO( offsetChngesIntervall != null && offsetChngesInterval.size() > 0 )
to make sure that the list isn't empty. Perhaps also a check that it is not null.

check multiple files md5s in native c++

guys whats problem with this source?
i use this to check MD5s but only first md5 checked?
if(md5("main\iw_00") != "92d86b9137f249a51ce14256362514bc"
|| md5("main\iw_01") != "80e13bc5fb2078728405bfae9b529414"
|| md5("main\iw_02") != "be2c0a1cbf5858e978dc39a8e00bff62"
|| md5("main\iw_03") != "223fc8672db4e0d3ef38f8348b9be6da"
|| md5("main\iw_04") != "8fde7ed770c6136039206edbb24f5b8a")
Compare string literals by pointer is usually meaningless. Try strcmp or something like.
strcmp(md5("main\iw_01"), "80e13bc5fb2078728405bfae9b529414") != 0
main\iw01 is most probably not what you really want. \ starts an escape sequence. In most cases the correct usage (especially since \i doesn't exist) would be main\\iw01.
This condition is true all the time , you can not use ! and || togther .

How to make =NULL work in SQLite?

Given the following table:
Table: Comedians
=================
Id First Middle Last
--- ------- -------- -------
1 Bob NULL Sagat
2 Jerry Kal Seinfeld
I want to make the following prepared query:
SELECT * FROM Comedians WHERE Middle=?
work for all cases. It currently does not work for the case where I pass NULL via sqlite3_bind_null. I realize that the query to actually search for NULL values uses IS NULL, but that would mean that I cannot use the prepared query for all cases. I would actually have to change the query depending on the input, which largely defeats the purpose of the prepared query. How do I do this? Thanks!
You can use the IS operator instead of =.
SELECT * FROM Comedians WHERE Middle IS ?
Nothing matches = NULL. The only way to check that is with IS NULL.
You can do a variety of things, but the straight forward one is...
WHERE
middle = ?
OR (middle IS NULL and ? IS NULL)
If there is a value you know NEVER appears, you can change that to...
WHERE
COALESCE(middle, '-') = COALESCE(?, '-')
But you need a value that literally NEVER appears. Also, it obfuscates the use of indexes, but the OR version can often suck as well (I don't know how well SQLite treats it).
All things equal, I recommend the first version.
NULL is not a value, but an attribute of a field. Instead use
SELECT * FROM Comedians WHERE Middle IS NULL
If you want match everything on NULL
SELECT * FROM Comedians WHERE Middle=IfNull(?, Middle)
if want match none on NULL
SELECT * FROM Comedians WHERE Middle=IfNull(?, 'DUMMY'+Middle)
See this answer: https://stackoverflow.com/a/799406/30225