<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SQL SELECT -&amp;gt; If (numrows &amp;gt; 0) in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310929#M82011</link>
    <description>Another quick thing carrying on from the above. 
&lt;BR /&gt;Ive been trying to get it to insert a row when the IF statements returns false and update the row when it returns true. I imagine I will need MySQL row somewhere along the line but have had no luck as of yet.
&lt;BR /&gt;Any response would be much appreciated.
&lt;BR /&gt;Thanks in advance</description>
    <pubDate>Tue, 05 Jul 2011 15:51:56 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2011-07-05T15:51:56Z</dc:date>
    <item>
      <title>SQL SELECT -&gt; If (numrows &gt; 0)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310926#M82008</link>
      <description>Hi,
&lt;BR /&gt;Im using the Java version and have got Talend connected to a MySQL database. What I want to know is how to perform a SELECT SQL statement, and if it returns one or more rows do one thing, else if it returns no rows do another. It sounds simple and probably is but Ive searched the net and google and have had no luck.
&lt;BR /&gt;Thanks in advance</description>
      <pubDate>Sat, 16 Nov 2024 12:49:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310926#M82008</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T12:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: SQL SELECT -&gt; If (numrows &gt; 0)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310927#M82009</link>
      <description>Hi 
&lt;BR /&gt;You can use the global variable nb_line of tMyslqInput which counts the total number of selected rows. For example: 
&lt;BR /&gt;tMysqlInput_1--main--tLogRow 
&lt;BR /&gt; | 
&lt;BR /&gt;onsubjobok 
&lt;BR /&gt; | 
&lt;BR /&gt;tJava--runIf---do one thing 
&lt;BR /&gt; --RunIf---do another thing 
&lt;BR /&gt;on tJava: 
&lt;BR /&gt; 
&lt;PRE&gt;int nb_line=((Integer)globalMap.get("tMysqlInput_1_NB_LINE"));&lt;BR /&gt;if(nb_line&amp;gt;0){&lt;BR /&gt;globalMap.put("hasRows",true);&lt;BR /&gt;}else{&lt;BR /&gt;globalMap.put("hasRows",true);&lt;BR /&gt;}&lt;/PRE&gt; 
&lt;BR /&gt;set the condition of the first runIf: 
&lt;BR /&gt;(Boolean)globalMap.get("hasRows") 
&lt;BR /&gt;set the condition of the second runIf: 
&lt;BR /&gt;!(Boolean)globalMap.get("hasRows") 
&lt;BR /&gt; 
&lt;BR /&gt;Best regards 
&lt;BR /&gt;Shong</description>
      <pubDate>Tue, 05 Jul 2011 10:12:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310927#M82009</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-05T10:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: SQL SELECT -&gt; If (numrows &gt; 0)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310928#M82010</link>
      <description>Many thanks, worked perfectly.</description>
      <pubDate>Tue, 05 Jul 2011 10:28:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310928#M82010</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-05T10:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: SQL SELECT -&gt; If (numrows &gt; 0)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310929#M82011</link>
      <description>Another quick thing carrying on from the above. 
&lt;BR /&gt;Ive been trying to get it to insert a row when the IF statements returns false and update the row when it returns true. I imagine I will need MySQL row somewhere along the line but have had no luck as of yet.
&lt;BR /&gt;Any response would be much appreciated.
&lt;BR /&gt;Thanks in advance</description>
      <pubDate>Tue, 05 Jul 2011 15:51:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310929#M82011</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-05T15:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: SQL SELECT -&gt; If (numrows &gt; 0)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310930#M82012</link>
      <description>&lt;BLOCKQUOTE&gt; 
 &lt;TABLE border="1"&gt; 
  &lt;TBODY&gt; 
   &lt;TR&gt; 
    &lt;TD&gt;Another quick thing carrying on from the above. &lt;BR /&gt;Ive been trying to get it to insert a row when the IF statements returns false and update the row when it returns true. I imagine I will need MySQL row somewhere along the line but have had no luck as of yet.&lt;BR /&gt;Any response would be much appreciated.&lt;BR /&gt;Thanks in advance&lt;/TD&gt; 
   &lt;/TR&gt; 
  &lt;/TBODY&gt; 
 &lt;/TABLE&gt; 
&lt;/BLOCKQUOTE&gt; 
&lt;BR /&gt;Hi 
&lt;BR /&gt;Sorry, I don't understand your new question.;( 
&lt;BR /&gt;Best regards 
&lt;BR /&gt;Shong</description>
      <pubDate>Wed, 06 Jul 2011 12:57:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310930#M82012</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-06T12:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: SQL SELECT -&gt; If (numrows &gt; 0)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310931#M82013</link>
      <description>Sorry I will try and be clearer. 
&lt;BR /&gt;Assuming you understand PHP syntax, below is a simplified version of I want to be able to do within Talend. 
&lt;BR /&gt; 
&lt;PRE&gt;	$sql = " select * from departments  where country_id = 'UK'";&lt;BR /&gt;        $result = mysql_query($sql);&lt;BR /&gt;        $num_rows = mysql_num_rows($result);&lt;BR /&gt;	if ($num_rows == 1)&lt;BR /&gt;	{&lt;BR /&gt;                $row = mysql_fetch_array($result);&lt;BR /&gt;                $id = $row;&lt;BR /&gt;                $sql = "update departments set dept_name = 'xxx', dept_type = 'xxx' where dept_id = '$id'";&lt;BR /&gt;                mysql_query($sql);&lt;BR /&gt;	}&lt;BR /&gt;	else&lt;BR /&gt;	{&lt;BR /&gt;                $sql = "insert into departments (dept_name, dept_type, deptfloor) values ($deptname, $depttype, $deptfloor)";&lt;BR /&gt;                mysql_query($sql);&lt;BR /&gt;	}&lt;/PRE&gt; 
&lt;BR /&gt;The code may not be correct in syntax as I typed it out quickly for this example but hopefully itll give you a greater understanding of what I want to achieve. 
&lt;BR /&gt;Thanks alot.</description>
      <pubDate>Thu, 07 Jul 2011 10:58:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310931#M82013</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-07T10:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: SQL SELECT -&gt; If (numrows &gt; 0)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310932#M82014</link>
      <description>Hi aaronb 
&lt;BR /&gt;I came up with a solution to your problem however I am not sure what components you are using so if you need help changing things around just let me know. 
&lt;BR /&gt;tForeach (I use to execute multiple queries) 
&lt;BR /&gt;new query on every line and can't have new lines eg. 
&lt;BR /&gt;"SELECT * FROM Table" 
&lt;BR /&gt;"SELECT * FROM Table2" 
&lt;BR /&gt;-- have as many of these as you need (Like I said I don't know what your input queries will be so we can always change this) -- 
&lt;BR /&gt;NOT 
&lt;BR /&gt;"SELECT * 
&lt;BR /&gt;FROM Table" 
&lt;BR /&gt;"SELECT * 
&lt;BR /&gt;FROM Table2" 
&lt;BR /&gt;tMySQL_input_5 (!This is to get the count from the query first!) 
&lt;BR /&gt;query - ((String)globalMap.get("tForeach_1_CURRENT_VALUE")) 
&lt;BR /&gt;schema would be count and other hard coded values 
&lt;BR /&gt;eg. 
&lt;BR /&gt;"SELECT COUNT(*), 'uk' as country from table1" 
&lt;BR /&gt;where uk will be used in a query later on. 
&lt;BR /&gt;tJavaRow_1 code 
&lt;BR /&gt; 
&lt;PRE&gt;if(!String.valueOf(input_row.count).equals("1"))&lt;BR /&gt;{&lt;BR /&gt;globalMap.put("query", "SELECT * FROM table where country = "+input_row.country+"");   // input_row.country is the hard coded value from the query&lt;BR /&gt;globalMap.put("TF", "false");&lt;BR /&gt;}&lt;BR /&gt;else if(String.valueOf(input_row.count).equals("1"))&lt;BR /&gt;{&lt;BR /&gt;globalMap.put("query", "SELECT * FROM table where country = "+input_row.country+"");   // input_row.country is the hard coded value from the query&lt;BR /&gt;globalMap.put("TF", "true");&lt;BR /&gt;}&lt;/PRE&gt; 
&lt;BR /&gt;if - to -&amp;gt; tMySQLInput_6 
&lt;BR /&gt;globalMap.get("TF").equals("true") 
&lt;BR /&gt; 
&lt;BR /&gt;if - to -&amp;gt; tMySQLInput_7 
&lt;BR /&gt;globalMap.get("TF").equals("false") 
&lt;BR /&gt;tMySQLInput_6 would be your update. 
&lt;BR /&gt;query - (String)globalMap.get("query") 
&lt;BR /&gt;and tMySQLOutput_1 would be set to update 
&lt;BR /&gt;tMySQLInput_7 would be your insert. 
&lt;BR /&gt;query - (String)globalMap.get("query") 
&lt;BR /&gt;and tMySQLOutput_2 would be set to insert 
&lt;BR /&gt;Here is the image of the job below: 
&lt;BR /&gt; 
&lt;IMG src="https://community.qlik.com/" /&gt; 
&lt;BR /&gt; 
&lt;BR /&gt;I Hope this gets you on the right track there may be an easier way of doing this, I just thought of this solution quickly as earlier in this post you said you wanted to use select statements that can have different values added into them. 
&lt;BR /&gt; 
&lt;BR /&gt;Or if you want to use the nb line to count the rows we can also do it that way 
&lt;BR /&gt;Regards, 
&lt;BR /&gt;Brandon</description>
      <pubDate>Thu, 07 Jul 2011 13:35:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/SQL-SELECT-gt-If-numrows-gt-0/m-p/2310932#M82014</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-07T13:35:37Z</dc:date>
    </item>
  </channel>
</rss>

