cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
dadawasozo
Level IV

issue to insert date variable into customsql

Hi,

I want to set the start and end datetime as variable then insert into customsql. in method one below, JMP Alert of converting issue. When I simply hard coded the start and end date as variable, it run without issue. I check both the start and end date type in both method, both are string(). Event the custom sql after substitute into are identical. I cannot find out why the method one not working on date variable. Can someone help?? I really dont want to have to manually change the date everyday. How can I make method 1 works?

dadawasozo_0-1687268578976.png

method 1 & 2

//method 1 to define start and end  date (not working)
sdate= format(today()-inhours(24), "m/d/y");  //method 1
tstart = sdate || " 19:13:01 PM";// method 1

edate= format(today(), "m/d/y"); //method 1
tend = edate || " 12:13:00 AM"; //method 1

//method 2 to define start and end date (working)
tend= "06/19/2023 19:13:01 PM"; //method 2
tstart= "06/19/2023 12:13:00 AM";  //method2

Assign(sql_str,  "SELECT t1.[test], CAST(t2.[testplan ] AS INTEGER), bla bla bla
WHERE  (  (  ( t1.[end_time] >= &tstart  )  AND  ( t1.[end_time] <= &tend  )  )  ) ;"
);
substitute Into(sql_str, "&tstart", "'"||tstart ||"'");
substitute Into(sql_str, "&tend", "'"||tend ||"'");
dt = New SQL Query (Version(130), connection("mydatabaseinfor"), QueryName("mysqlname" ), CustomSQL(sql_str)) << Run Foreground;

4 REPLIES 4
jthi
Super User

Re: issue to insert date variable into customsql

Does your method1 provide you with correct strings? It could be that the date is formatted incorrectly.

Names Default To Here(1);

sdate = today()-inhours(24);
m = Month(sdate);
y = Year(sdate);
d = Day(sdate);
sdate = Eval Insert("^m^/^d^/^y^");
tstart = sdate || " 19:13:01 PM";

 

-Jarmo
dadawasozo
Level IV

Re: issue to insert date variable into customsql

the method1 give the same identical string as method2 when I do show().

I tried your method, and still getting same error.

jthi
Super User

Re: issue to insert date variable into customsql

Checking your script again, you have tstart and tend different on method1 and method2. Maybe it is causing issues during the query?

-Jarmo
dadawasozo
Level IV

Re: issue to insert date variable into customsql

dont think so, I tried same as method 2 but still have same issue. 
could it be bug in jmp pro 16.2?