<?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 query script problem with date format in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453645#M70047</link>
    <description>&lt;P&gt;Thank you very much for your answer. It returns well what I want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jan 2022 17:39:30 GMT</pubDate>
    <dc:creator>Teissduc16</dc:creator>
    <dc:date>2022-01-24T17:39:30Z</dc:date>
    <item>
      <title>SQL query script problem with date format</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453397#M70033</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a biginner on JSL. I'm mixing a script with a SQL Query. My query conditionned by two date. But when I run it the assignement of my date deosn't work. The fild with the date is _TIMESTAMP and the format of the date is yyyy-mm-dd hh:mm:ss. When I run it with the dates inside the query of course it works. I need this script because I have to do the same thing for numerous tables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the script :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;RunScript= Expr( 
  sql_statement=evalinsert("SELECT * FROM table_SQL WHERE  _TIMESTAMP &amp;gt;= '^start^' AND  _TIMESTAMP &amp;lt; '^end^' ");
  start=(2021-12-15 00:00:00); 
  end=(2021-12-18 00:00:00); 
  Open Database("Driver=§§§§§§§§§§§§§§§§§§§§§§§§", 
  sql_statement,"table_name_1"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have blinded the sql connexion parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:09:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453397#M70033</guid>
      <dc:creator>Teissduc16</dc:creator>
      <dc:date>2023-06-09T18:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query script problem with date format</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453428#M70035</link>
      <description>&lt;P&gt;Welcome to the community&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/36148"&gt;@Teissduc16&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of small things that might help:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You probably want to define start and end before you use them in the eval insert() line.&lt;/LI&gt;
&lt;LI&gt;To make sure the date shows up in a format SQL understands, you probably want to format dates as strings before putting them in the sql statement&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;start=("2021-12-15 00:00:00"); 
end=format(date dmy(1,1,2021), "yyyy-mm-dd hh:mm:ss");
sql_statement=evalinsert("SELECT * FROM table_SQL WHERE  _TIMESTAMP &amp;gt;= '^start^' AND  _TIMESTAMP &amp;lt; '^end^' ");
show(sql_statement);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jan 2022 12:51:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453428#M70035</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2022-01-24T12:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query script problem with date format</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453429#M70036</link>
      <description>&lt;P&gt;sql_statement will error if you don't have start and end defined before the eval insert statement, also change start and end to strings&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

//this will error because it is before start and end variable definition
//sql_statement=evalinsert("SELECT * FROM table_SQL WHERE  _TIMESTAMP &amp;gt;= '^start^' AND  _TIMESTAMP &amp;lt; '^end^' ");

start = "2021-12-15 00:00:00"; 
end = "2021-12-18 00:00:00"; 
sql_statement=evalinsert("SELECT * FROM table_SQL WHERE  _TIMESTAMP &amp;gt;= '^start^' AND  _TIMESTAMP &amp;lt; '^end^' ");
show(sql_statement);
//sql_statement = "SELECT * FROM table_SQL WHERE _TIMESTAMP &amp;gt;= '2021-12-15 00:00:00' AND _TIMESTAMP &amp;lt; '2021-12-18 00:00:00' ";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jan 2022 12:51:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453429#M70036</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-01-24T12:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query script problem with date format</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453645#M70047</link>
      <description>&lt;P&gt;Thank you very much for your answer. It returns well what I want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 17:39:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-script-problem-with-date-format/m-p/453645#M70047</guid>
      <dc:creator>Teissduc16</dc:creator>
      <dc:date>2022-01-24T17:39:30Z</dc:date>
    </item>
  </channel>
</rss>

