<?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: [resolved] Iterate over different dates, using date in SQL query in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246287#M31854</link>
    <description>tLoop--iterate--tJava--oncomponent--&amp;gt;tYourDBInput--main--tLogRow 
&lt;BR /&gt;On tLoop, set the loop from 1 to 150 with Step 1.&amp;nbsp; 
&lt;BR /&gt;on tJava: 
&lt;BR /&gt;Context.YourDateParameter=TalendDate.addDate( 
&lt;FONT size="2"&gt;Context.YourDateParameter,&lt;/FONT&gt; 
&lt;FONT size="2"&gt;Context.YourDateParameter-1&lt;/FONT&gt; 
&lt;FONT size="2"&gt;, ""dd");&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;//Define a context variable&amp;nbsp;&lt;/FONT&gt; 
&lt;FONT size="2"&gt;YourDateParameter and set a default value to it or load its value at run time.&lt;/FONT&gt; 
&lt;BR /&gt;on tYourDBInput, define the query as: 
&lt;BR /&gt; 
&lt;PRE&gt;"Select x,y,z from table A JOIN table B ON x=x and '"+context.YourDateParameter+"' between startdate and enddate"&lt;/PRE&gt; 
&lt;BR /&gt;Shong</description>
    <pubDate>Tue, 27 Jan 2015 04:04:02 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-01-27T04:04:02Z</dc:date>
    <item>
      <title>[resolved] Iterate over different dates, using date in SQL query</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246284#M31851</link>
      <description>Hi,
&lt;BR /&gt;I have a query which looks like
&lt;BR /&gt;Select x,y,z from table A JOIN table B ON x=x and "date" between startdate and enddate
&lt;BR /&gt;This "date" parameter is an incremental date parameter which would repeat for around 150 sequential days(EG - 2014-08-01 to 2015-01-27).
&lt;BR /&gt;I thought of using tForeach component, but it would be difficult to manually enter all 150 days in each row.
&lt;BR /&gt;Is there any other way?
&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 27 Jan 2015 01:53:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246284#M31851</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-27T01:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Iterate over different dates, using date in SQL query</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246285#M31852</link>
      <description>Hi
&lt;BR /&gt;- I don't understand your requirement well, so I can't give you an precise answer, but if you want to populate the interval days between startdate and enddate, you can use TalendDate.differDate() function.
&lt;BR /&gt;- tLoop can be used to do iteration operation.
&lt;BR /&gt;- If you need to add date, use TalendDate.addDate() function.
&lt;BR /&gt;Best regards
&lt;BR /&gt;Shong</description>
      <pubDate>Tue, 27 Jan 2015 03:36:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246285#M31852</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-27T03:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Iterate over different dates, using date in SQL query</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246286#M31853</link>
      <description>Hi Shong, 
&lt;BR /&gt;Here is the requirement. 
&lt;BR /&gt;I have a query for which date is like a parameter and the query needs to be repeated for each dates for 150 days. So sequence could be 
&lt;BR /&gt;Select x,y,z from table A JOIN table B ON x=x and "2014-08-01" between startdate and enddate 
&lt;BR /&gt;Select x,y,z from table A JOIN table B ON x=x and "2014-08-02" between startdate and enddate 
&lt;BR /&gt;Select x,y,z from table A JOIN table B ON x=x and "2014-08-03" between startdate and enddate 
&lt;BR /&gt;. 
&lt;BR /&gt;. 
&lt;BR /&gt;. 
&lt;BR /&gt;Select x,y,z from table A JOIN table B ON x=x and "2015-01-25" between startdate and enddate 
&lt;BR /&gt;I would be using this query in tRedshift component. So I should be able to add this parameter in the query.</description>
      <pubDate>Tue, 27 Jan 2015 03:42:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246286#M31853</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-27T03:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Iterate over different dates, using date in SQL query</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246287#M31854</link>
      <description>tLoop--iterate--tJava--oncomponent--&amp;gt;tYourDBInput--main--tLogRow 
&lt;BR /&gt;On tLoop, set the loop from 1 to 150 with Step 1.&amp;nbsp; 
&lt;BR /&gt;on tJava: 
&lt;BR /&gt;Context.YourDateParameter=TalendDate.addDate( 
&lt;FONT size="2"&gt;Context.YourDateParameter,&lt;/FONT&gt; 
&lt;FONT size="2"&gt;Context.YourDateParameter-1&lt;/FONT&gt; 
&lt;FONT size="2"&gt;, ""dd");&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;//Define a context variable&amp;nbsp;&lt;/FONT&gt; 
&lt;FONT size="2"&gt;YourDateParameter and set a default value to it or load its value at run time.&lt;/FONT&gt; 
&lt;BR /&gt;on tYourDBInput, define the query as: 
&lt;BR /&gt; 
&lt;PRE&gt;"Select x,y,z from table A JOIN table B ON x=x and '"+context.YourDateParameter+"' between startdate and enddate"&lt;/PRE&gt; 
&lt;BR /&gt;Shong</description>
      <pubDate>Tue, 27 Jan 2015 04:04:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246287#M31854</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-27T04:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Iterate over different dates, using date in SQL query</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246288#M31855</link>
      <description>Hi Shong, 
&lt;BR /&gt;Thanks for reply. 
&lt;BR /&gt;I am actually trying out the same steps. 
&lt;BR /&gt;tSetGlobalVar_1 -- tLoop -- TJava -- tSQL 
&lt;BR /&gt;The only problem that I am working on currently, is passing parameters. 
&lt;BR /&gt; 
&lt;BR /&gt; 
&lt;BLOCKQUOTE&gt; 
 &lt;TABLE border="1"&gt; 
  &lt;TBODY&gt; 
   &lt;TR&gt; 
    &lt;TD&gt;In tSetGlobalVar_1 , I have set startDate = "2014-08-01"&lt;/TD&gt; 
   &lt;/TR&gt; 
  &lt;/TBODY&gt; 
 &lt;/TABLE&gt; 
&lt;/BLOCKQUOTE&gt; 
&lt;BR /&gt;tJAVA contains this 
&lt;BR /&gt; 
&lt;BLOCKQUOTE&gt; 
 &lt;TABLE border="1"&gt; 
  &lt;TBODY&gt; 
   &lt;TR&gt; 
    &lt;TD&gt;String dt_string = "";&lt;BR /&gt;Date current_dt = TalendDate.parseDate("yyyy-MM-dd", (String)globalMap.get("startDate"));&lt;BR /&gt;current_dt = TalendDate.addDate(current_dt, 1, "dd");&lt;BR /&gt;dt_string = current_dt.toString();&lt;BR /&gt;globalMap.put("startDate", dt_string);&lt;/TD&gt; 
   &lt;/TR&gt; 
  &lt;/TBODY&gt; 
 &lt;/TABLE&gt; 
&lt;/BLOCKQUOTE&gt; 
&lt;BR /&gt; 
&lt;BR /&gt;It is throwing me error, when I run it. I suspect the reason is format of current_dt variable. 
&lt;BR /&gt;When I print "current_dt" on screen, this is what i get "Fri Aug 01 00:00:00 SGT 2014" 
&lt;BR /&gt;When I convert "current_dt" to string and set GlobalVar "startDate", it actually stores in this format and in next loop when it retrieves the values, it fails to parse 
&lt;BR /&gt;as parse expects "yyyy-MM-dd" format</description>
      <pubDate>Tue, 27 Jan 2015 04:16:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246288#M31855</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-27T04:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Iterate over different dates, using date in SQL query</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246289#M31856</link>
      <description>&lt;PRE&gt;dt_string = current_dt.toString();&lt;/PRE&gt;
&lt;BR /&gt;If you print dt_string after converting date to a string, you will see it is not the format "
&lt;FONT size="1"&gt;&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;yyyy-MM-dd&lt;/FONT&gt;&lt;/FONT&gt;
&lt;FONT size="2"&gt;", change this code to&amp;nbsp;&lt;/FONT&gt;
&lt;BR /&gt;
&lt;PRE&gt;dt_string=TalendDate.formatDate("yyyy-MM-dd", current_dt);&lt;BR /&gt;&lt;/PRE&gt;
&lt;BR /&gt;
&lt;FONT size="2"&gt;Shong&lt;/FONT&gt;</description>
      <pubDate>Tue, 27 Jan 2015 04:26:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246289#M31856</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-27T04:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Iterate over different dates, using date in SQL query</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246290#M31857</link>
      <description>Thank you Shong</description>
      <pubDate>Wed, 28 Jan 2015 01:47:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Iterate-over-different-dates-using-date-in-SQL-query/m-p/2246290#M31857</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-28T01:47:46Z</dc:date>
    </item>
  </channel>
</rss>

