<?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: How to loop when querying date? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-loop-when-querying-date/m-p/723947#M90599</link>
    <description>&lt;P&gt;Depending on your sql you might be able to deduct index from the date (might require trunc / modifying your query a bit)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

start_date = 01Jul2023;
end_date = 31Jan2024;

datecount = Date Difference(start_date, end_date, "Day");

Show(As Date(start_date + In Days(datecount)));

sql_template = "\[select sysdate - ^i^ startdate, sysdate - ^i - 1^ enddate from dual]\";

For(i = 1, i &amp;lt;= datecount, i++,
	cur_sql = Eval Insert(sql_template);
	Show(cur_sql);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also you most likely want to concatenate the query results inside the query and adding some simple print logging can be helpful (I usually print at least: current index/date which is being queried, how many rows you got back and how long the query took).&lt;/P&gt;</description>
    <pubDate>Tue, 13 Feb 2024 06:58:32 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-02-13T06:58:32Z</dc:date>
    <item>
      <title>How to loop when querying date?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-loop-when-querying-date/m-p/723908#M90593</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;I am trying to query the database using JMP. In my query, I manually change the dateNow value from day 1 to 30 then run the script. But I needed to create another one that would loop all through the days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I create a loop that queries every date starting from July 2023 to January 2024?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dateNow = "01/11/2024";

dt = Open Database( "DSN=databasename;UID=root;PWD=admin;APP=JMP;DATABASE=dbSample").
"select distinct name, age, sex, address
from db1
where date between '" || dateNow || " 00:00:00 AM' and '" || dateNow || " 11:59:59 PM'",  
"raw" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 23:56:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-loop-when-querying-date/m-p/723908#M90593</guid>
      <dc:creator>UserID16644</dc:creator>
      <dc:date>2024-02-12T23:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop when querying date?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-loop-when-querying-date/m-p/723928#M90598</link>
      <description>&lt;P&gt;Here is my solution.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );


For( theDate = Informat( "01/07/2023", "d/m/y" ), theDate &amp;lt;= Informat( "31/1/2024", "d/m/y" ),
	theDate = theDate + In Days( 1 ),
	
	// Create the dateNow variable from the index variable "theDate"
	dateNow = Format( theDate, "d/m/y" );

dt = Open Database( "DSN=databasename;UID=root;PWD=admin;APP=JMP;DATABASE=dbSample").
"select distinct name, age, sex, address
from db1
where date between '" || dateNow || " 00:00:00 AM' and '" || dateNow || " 11:59:59 PM'",  
"raw" );

);&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 03:41:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-loop-when-querying-date/m-p/723928#M90598</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-02-13T03:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop when querying date?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-loop-when-querying-date/m-p/723947#M90599</link>
      <description>&lt;P&gt;Depending on your sql you might be able to deduct index from the date (might require trunc / modifying your query a bit)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

start_date = 01Jul2023;
end_date = 31Jan2024;

datecount = Date Difference(start_date, end_date, "Day");

Show(As Date(start_date + In Days(datecount)));

sql_template = "\[select sysdate - ^i^ startdate, sysdate - ^i - 1^ enddate from dual]\";

For(i = 1, i &amp;lt;= datecount, i++,
	cur_sql = Eval Insert(sql_template);
	Show(cur_sql);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also you most likely want to concatenate the query results inside the query and adding some simple print logging can be helpful (I usually print at least: current index/date which is being queried, how many rows you got back and how long the query took).&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 06:58:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-loop-when-querying-date/m-p/723947#M90599</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-02-13T06:58:32Z</dc:date>
    </item>
  </channel>
</rss>

