cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-453397%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EProblem%20mit%20dem%20SQL-Abfrageskript%20mit%20dem%20Datumsformat%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-453397%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHallo%2C%3C%2FP%3E%3CP%3EIch%20bin%20ein%20Fan%20von%20JSL.%20Ich%20mische%20ein%20Skript%20mit%20einer%20SQL-Abfrage.%20Meine%20Anfrage%20ist%20durch%20zwei%20Datumsangaben%20bedingt.%20Aber%20wenn%20ich%20es%20ausf%C3%BChre%2C%20funktioniert%20die%20Zuweisung%20meines%20Datums%20nicht.%20Das%20Feld%20mit%20dem%20Datum%20ist%20_TIMESTAMP%20und%20das%20Format%20des%20Datums%20ist%20jjjj-mm-tt%20hh%3Amm%3Ass.%20Wenn%20ich%20es%20mit%20den%20Daten%20in%20der%20Abfrage%20ausf%C3%BChre%2C%20funktioniert%20es%20nat%C3%BCrlich.%20Ich%20brauche%20dieses%20Skript%2C%20weil%20ich%20f%C3%BCr%20zahlreiche%20Tabellen%20dasselbe%20tun%20muss.%3C%2FP%3E%3CP%3EHier%20ist%20das%20Skript%3A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ERunScript%3D%20Expr(%20%0A%20%20sql_statement%3Devalinsert(%22SELECT%20*%20FROM%20table_SQL%20WHERE%20%20_TIMESTAMP%20%26gt%3B%3D%20'%5Estart%5E'%20AND%20%20_TIMESTAMP%20%26lt%3B%20'%5Eend%5E'%20%22)%3B%0A%20%20start%3D(2021-12-15%2000%3A00%3A00)%3B%20%0A%20%20end%3D(2021-12-18%2000%3A00%3A00)%3B%20%0A%20%20Open%20Database(%22Driver%3D%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%C2%A7%22%2C%20%0A%20%20sql_statement%2C%22table_name_1%22))%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EIch%20habe%20die%20SQL-Verbindungsparameter%20geblendet.%3C%2FP%3E%3CP%3EMit%20freundlichen%20Gr%C3%BC%C3%9Fe%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-453397%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EAutomatisierung%20und%20Skripterstellung%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDatenzugriff%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMassenanpassung%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-453645%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20SQL-Abfrageskriptproblem%20mit%20Datumsformat%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-453645%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20danke%20Ihnen%20sehr%20f%C3%BCr%20Ihre%20Antwort.%20Es%20gibt%20gut%20zur%C3%BCck%2C%20was%20ich%20will.%3C%2FP%3E%3CP%3EGr%C3%BC%C3%9Fe%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-453429%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20SQL-Abfrageskriptproblem%20mit%20Datumsformat%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-453429%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3Esql_statement%20gibt%20einen%20Fehler%20aus%2C%20wenn%20Sie%20vor%20der%20eval%20insert-Anweisung%20nicht%20Start%20und%20Ende%20definiert%20haben.%20%C3%84ndern%20Sie%20au%C3%9Ferdem%20Start%20und%20Ende%20in%20Zeichenfolgen%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0A%2F%2Fthis%20will%20error%20because%20it%20is%20before%20start%20and%20end%20variable%20definition%0A%2F%2Fsql_statement%3Devalinsert(%22SELECT%20*%20FROM%20table_SQL%20WHERE%20%20_TIMESTAMP%20%26gt%3B%3D%20'%5Estart%5E'%20AND%20%20_TIMESTAMP%20%26lt%3B%20'%5Eend%5E'%20%22)%3B%0A%0Astart%20%3D%20%222021-12-15%2000%3A00%3A00%22%3B%20%0Aend%20%3D%20%222021-12-18%2000%3A00%3A00%22%3B%20%0Asql_statement%3Devalinsert(%22SELECT%20*%20FROM%20table_SQL%20WHERE%20%20_TIMESTAMP%20%26gt%3B%3D%20'%5Estart%5E'%20AND%20%20_TIMESTAMP%20%26lt%3B%20'%5Eend%5E'%20%22)%3B%0Ashow(sql_statement)%3B%0A%2F%2Fsql_statement%20%3D%20%22SELECT%20*%20FROM%20table_SQL%20WHERE%20_TIMESTAMP%20%26gt%3B%3D%20'2021-12-15%2000%3A00%3A00'%20AND%20_TIMESTAMP%20%26lt%3B%20'2021-12-18%2000%3A00%3A00'%20%22%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-453428%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20SQL-Abfrageskriptproblem%20mit%20Datumsformat%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-453428%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EWillkommen%20in%20der%20Community%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F36148%22%20target%3D%22_blank%22%3E%20%40Teissduc16%3C%2FA%3E%20%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEin%20paar%20kleine%20Dinge%2C%20die%20helfen%20k%C3%B6nnten%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWahrscheinlich%20m%C3%B6chten%20Sie%20Start%20und%20Ende%20definieren%2C%20bevor%20Sie%20sie%20in%20der%20Zeile%20eval%20insert()%20verwenden.%3C%2FLI%3E%0A%3CLI%3EUm%20sicherzustellen%2C%20dass%20das%20Datum%20in%20einem%20Format%20angezeigt%20wird%2C%20das%20SQL%20versteht%2C%20m%C3%B6chten%20Sie%20Datumsangaben%20wahrscheinlich%20als%20Zeichenfolgen%20formatieren%2C%20bevor%20Sie%20sie%20in%20die%20SQL-Anweisung%20einf%C3%BCgen%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EHier%20ist%20ein%20Beispiel%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Estart%3D(%222021-12-15%2000%3A00%3A00%22)%3B%20%0Aend%3Dformat(date%20dmy(1%2C1%2C2021)%2C%20%22yyyy-mm-dd%20hh%3Amm%3Ass%22)%3B%0Asql_statement%3Devalinsert(%22SELECT%20*%20FROM%20table_SQL%20WHERE%20%20_TIMESTAMP%20%26gt%3B%3D%20'%5Estart%5E'%20AND%20%20_TIMESTAMP%20%26lt%3B%20'%5Eend%5E'%20%22)%3B%0Ashow(sql_statement)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Teissduc16
Level I

SQL query script problem with date format

Hello, 

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. 

Here is the script : 

RunScript= Expr( 
  sql_statement=evalinsert("SELECT * FROM table_SQL WHERE  _TIMESTAMP >= '^start^' AND  _TIMESTAMP < '^end^' ");
  start=(2021-12-15 00:00:00); 
  end=(2021-12-18 00:00:00); 
  Open Database("Driver=§§§§§§§§§§§§§§§§§§§§§§§§", 
  sql_statement,"table_name_1"));

I have blinded the sql connexion parameters. 

Kind regards, 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: SQL query script problem with date format

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

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 >= '^start^' AND  _TIMESTAMP < '^end^' ");

start = "2021-12-15 00:00:00"; 
end = "2021-12-18 00:00:00"; 
sql_statement=evalinsert("SELECT * FROM table_SQL WHERE  _TIMESTAMP >= '^start^' AND  _TIMESTAMP < '^end^' ");
show(sql_statement);
//sql_statement = "SELECT * FROM table_SQL WHERE _TIMESTAMP >= '2021-12-15 00:00:00' AND _TIMESTAMP < '2021-12-18 00:00:00' ";
-Jarmo

View solution in original post

3 REPLIES 3
ih
Super User (Alumni) ih
Super User (Alumni)

Re: SQL query script problem with date format

Welcome to the community @Teissduc16,

 

A couple of small things that might help:

  • You probably want to define start and end before you use them in the eval insert() line.
  • 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

Here is an example:

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 >= '^start^' AND  _TIMESTAMP < '^end^' ");
show(sql_statement);
jthi
Super User

Re: SQL query script problem with date format

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

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 >= '^start^' AND  _TIMESTAMP < '^end^' ");

start = "2021-12-15 00:00:00"; 
end = "2021-12-18 00:00:00"; 
sql_statement=evalinsert("SELECT * FROM table_SQL WHERE  _TIMESTAMP >= '^start^' AND  _TIMESTAMP < '^end^' ");
show(sql_statement);
//sql_statement = "SELECT * FROM table_SQL WHERE _TIMESTAMP >= '2021-12-15 00:00:00' AND _TIMESTAMP < '2021-12-18 00:00:00' ";
-Jarmo
Teissduc16
Level I

Re: SQL query script problem with date format

Thank you very much for your answer. It returns well what I want. 

Regards

Recommended Articles