[resolved] tMysqlOutput insert or update

One Star

[resolved] tMysqlOutput insert or update

Hello,
I need to insert or update a mySQL table "SYPRM" depending of the result of a join between table "SYPRM" and string value of a CSV file
if the query returns no row => insert else update
SYPRM contains two strings columns :
PDESYPRM is the key
CPRSYPRM is a counter ... in string format
one column of the output file needs to be filed with "0001" if no row are returned from the query and value of CPRSYPRM + 1 on update

Can you give me an example of insert or update for my purpose ??
regards
Didier

Accepted Solutions
One Star

Re: [resolved] tMysqlOutput insert or update

actually I found the solution : I had an inner join in the input table linked to the tMySQLoutput "insert or update"
+
the evaluation condition triggering insert or update was based on a field of the tMySQLoutput so I always got null pointer exception ...

All Replies
One Star

Re: [resolved] tMysqlOutput insert or update

In Mysql there are several ways to do this and perhaps sometimes the simple way may be the easiest when using code in another product. What you could do is condition some code by something like
SET X_Count = Count(*) from table Y where A 'abcde'
I.e. get a count if there are no matching records
Remember that if there are no matching records then the count is likely to be the value of NULL and not 0.
however you could neatly structure either
IF X_Count = 0 then
Insert ........
ELSe
update ......
ENDIF
One Star

Re: [resolved] tMysqlOutput insert or update

@lesjar2509 : thanks for your answer but I want to use the component tMySQLoutput with the "insert or update" feature.
at the moment all the rows are inserted although the key already exists.
I have posted more screenshots
One Star

Re: [resolved] tMysqlOutput insert or update

actually I found the solution : I had an inner join in the input table linked to the tMySQLoutput "insert or update"
+
the evaluation condition triggering insert or update was based on a field of the tMySQLoutput so I always got null pointer exception ...