cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

Interactive date selection and filtering by SQL

AT
AT
Level V

I like to use JMP interative to get input start and end time and then use SQL to filter the data table. The parameter dateb and datee if defined as for instance '2017-10-10', '2017-11-11' works fine but when use assigned varaible dateb and datee, I don't get the correct filtering (empty tables).

I appreciate any help you can provide. Thanks.

------------------------------------

 

 

defuplim = Today();

deflowlim = Today() - In Days( 730 );

 

ww = New Window( "Pick Your Dates in yyyy-mm-dd format",

<<Modal,

<<return result,

V List Box(

Text Box( "Start Date:" ),

str1 = Number Edit Box(

deflowlim,

10,

<<SetFunction(

Function( {that},

lowlim = str1 << get

)

)

),

Text Box( "End Date:" ),

str2 = Number Edit Box(

defuplim,

10,

<<SetFunction(

Function( {this},

uplim = str2 << get

),

 

)

),

str1 << set format( Format( "yyyy-mm-dd" ) ),

str2 << set format( Format( "yyyy-mm-dd" ) )

),

H List Box( Button Box( "OK" ), Button Box( "Cancel" ) ),

       

);

 

 

dateb = As date(ww["str1"]);

datee = As date(ww["str2"]);

 

dateb = format(dateb,"yyyy-mm-dd");

datee = format(datee,"yyyy-mm-dd");

 

dt1 = Open Database(

"DSN=XXX;UID=root;PWD=xxxxx;",

"Select * from xyz where date(starttime) between 'dateb' and 'datee'","TMP"

 

);

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User


Re: Interactive date selection and filtering by SQL

See if this modification will work

defuplim = Today();
deflowlim = Today() - In Days( 730 );

ww = New Window( "Pick Your Dates in yyyy-mm-dd format", 
	<<Modal, 
	<<return result, 
	V List Box(
		Text Box( "Start Date:" ), 
		str1 = Number Edit Box(
			deflowlim, 
			10, 
			<<SetFunction(
				Function( {that}, 
					lowlim = str1 << get
				)
			)
		), 
		Text Box( "End Date:" ), 
		str2 = Number Edit Box(
			defuplim, 
			10, 
			<<SetFunction(
				Function( {this}, 
					uplim = str2 << get
				), 
			)
		), 
		str1 << set format( Format( "yyyy-mm-dd" ) ), 
		str2 << set format( Format( "yyyy-mm-dd" ) )
	), 
	H List Box( Button Box( "OK" ), Button Box( "Cancel" ) ),        
);

dateb = As Date( ww["str1"] );
datee = As Date( ww["str2"] );

dateb = Format( dateb, "yyyy-mm-dd" );
datee = Format( datee, "yyyy-mm-dd" );

Eval(
	Parse(
		"dt1 = Open Database(
	\!"DSN=XXX;UID=root;PWD=xxxxx;\!", 
	\!"Select * from xyz where date(starttime) between '"
		 || dateb || "' and '" || datee || "',\!"TMP\!");"
	)
);
Jim

View solution in original post

3 REPLIES 3
pmroz
Super User


Re: Interactive date selection and filtering by SQL

You need to convert your string dates back into dates for the database to understand them.  If this is Oracle you need a statement like:

sql_statement = evalinsert(
"Select * 
   from xyz 
  where date(starttime) between to_date('^dateb^', 'YYYY-MM-DD')
                            and to_date('^datee^', 'YYYY-MM-DD') ");

dt1 = Open Database("DSN=XXX;UID=root;PWD=xxxxx;", sql_statement);
txnelson
Super User


Re: Interactive date selection and filtering by SQL

See if this modification will work

defuplim = Today();
deflowlim = Today() - In Days( 730 );

ww = New Window( "Pick Your Dates in yyyy-mm-dd format", 
	<<Modal, 
	<<return result, 
	V List Box(
		Text Box( "Start Date:" ), 
		str1 = Number Edit Box(
			deflowlim, 
			10, 
			<<SetFunction(
				Function( {that}, 
					lowlim = str1 << get
				)
			)
		), 
		Text Box( "End Date:" ), 
		str2 = Number Edit Box(
			defuplim, 
			10, 
			<<SetFunction(
				Function( {this}, 
					uplim = str2 << get
				), 
			)
		), 
		str1 << set format( Format( "yyyy-mm-dd" ) ), 
		str2 << set format( Format( "yyyy-mm-dd" ) )
	), 
	H List Box( Button Box( "OK" ), Button Box( "Cancel" ) ),        
);

dateb = As Date( ww["str1"] );
datee = As Date( ww["str2"] );

dateb = Format( dateb, "yyyy-mm-dd" );
datee = Format( datee, "yyyy-mm-dd" );

Eval(
	Parse(
		"dt1 = Open Database(
	\!"DSN=XXX;UID=root;PWD=xxxxx;\!", 
	\!"Select * from xyz where date(starttime) between '"
		 || dateb || "' and '" || datee || "',\!"TMP\!");"
	)
);
Jim
AT
AT
Level V


Re: Interactive date selection and filtering by SQL

Thanks so much Jim. It worked perfectley.

Recommended Articles

No recommendations found