<?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: Open SQL database - user input (Dates) -  Error converting data type varchar to datetime. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Open-SQL-database-user-input-Dates-Error-converting-data-type/m-p/240225#M47470</link>
    <description>&lt;P&gt;I changed your window to be modal.&amp;nbsp; Otherwise the window displays and the SQL is attempted to be run all at once.&amp;nbsp; I'm not sure of the format needed for dates in SQL Server, so you may need to do a little research on that.&amp;nbsp; Copy the SQL statement that outputs to the log and try running it manually in a SQL server window.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nw = New Window( "test", &amp;lt;&amp;lt;modal(),
	H List Box(
		Text Box( "Start Date" ),
		a = Number Edit Box( 0 ),
		a &amp;lt;&amp;lt; set format( Format( "m/d/y" ) ),
		a &amp;lt;&amp;lt; set width( 12 ),
		a &amp;lt;&amp;lt; set( Today() ),
		Spacer Box( size( 10, 20 ) ),
		Text Box( "End Date" ),
		b = Number Edit Box( 0 ),
		b &amp;lt;&amp;lt; set format( Format( "m/d/y" ) ),
		b &amp;lt;&amp;lt; set width( 12 ),
		b &amp;lt;&amp;lt; set( Today() )
	),
	Spacer Box( size( 1, 20 ) ),    

	Button Box( "OK",
		start_date = Format( a &amp;lt;&amp;lt; get, "m/d/y" );
		end_date   = Format( b &amp;lt;&amp;lt; get, "m/d/y" );
	)
);

sql_statement = evalinsert("\[
EXEC dbo.listData @Criteria = '
&amp;lt;systemE&amp;gt;
  &amp;lt;Data Name="Alarm"&amp;gt;
    &amp;lt;Columns&amp;gt;
     &amp;lt;Column Name="Timestamp"/&amp;gt;  
    &amp;lt;/Columns&amp;gt;
    &amp;lt;Where&amp;gt;
     &amp;lt;Column Name="Resource" Operator="Like" Value="%a12%"/&amp;gt; 
    &amp;lt;/Where&amp;gt;
    &amp;lt;Projects&amp;gt;
      &amp;lt;Project Name="abc"/&amp;gt;
    &amp;lt;/Projects&amp;gt;
  &amp;lt;/Data&amp;gt;
&amp;lt;/systemE&amp;gt;'
,@StartDateTime = '^start_date^'
,@EndDateTime   = '^end_date^']\");

show(sql_statement);
// Uncomment the next line to run the command in SQL Server
//dta= Open database("DRIVER=SQL Server; SERVER=XXX;  Trusted_connection = Yes", sql_statement);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Other changes - if you want to use the ^xxx^ construct you need to enclose that in evalinsert().&amp;nbsp; I used the quoting escape characters \[ and ]\ so your SQL statement is a bit cleaner.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2020 16:37:08 GMT</pubDate>
    <dc:creator>pmroz</dc:creator>
    <dc:date>2020-01-06T16:37:08Z</dc:date>
    <item>
      <title>Open SQL database - user input (Dates) -  Error converting data type varchar to datetime.</title>
      <link>https://community.jmp.com/t5/Discussions/Open-SQL-database-user-input-Dates-Error-converting-data-type/m-p/240161#M47460</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to connect to a SQL database in a script using user input for dates.&lt;/P&gt;&lt;P&gt;When I run the script I get the following error -&amp;nbsp;&lt;/P&gt;&lt;P&gt;"[Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type varchar to datetime."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, how can I solve this problem?&lt;/P&gt;&lt;P&gt;Thx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;
nw = New Window( "test",
	H LIST BOX(
				       Text box("Start Date"),
				       a = numbereditbox(0),
                       a &amp;lt;&amp;lt; set format(format("m/d/y")),
                       a &amp;lt;&amp;lt; set width(12),
                       a &amp;lt;&amp;lt; set(today()),				     
				       Spacer Box( size( 10, 20 ) ),
				       Text box("End Date"),
				        b =  numbereditbox(0),
                       b &amp;lt;&amp;lt; set format(format("m/d/y")),
                       b &amp;lt;&amp;lt; set width(12),
                       b &amp;lt;&amp;lt; set(today())),
				       Spacer Box( size( 1, 20 ) ),    

	Button Box( "OK",
		farray = Eval List(
			{a &amp;lt;&amp;lt; get text, b &amp;lt;&amp;lt; get text}
		);
		nw &amp;lt;&amp;lt; close window;
	)
);

dta= Open database("DRIVER=SQL Server; SERVER=XXX;  Trusted_connection = Yes",
"
EXEC dbo.listData @Criteria = '
&amp;lt;systemE&amp;gt;
  &amp;lt;Data Name=\!"Alarm\!"&amp;gt;
    &amp;lt;Columns&amp;gt;
     &amp;lt;Column Name=\!"Timestamp\!"/&amp;gt;  
    &amp;lt;/Columns&amp;gt;
    &amp;lt;Where&amp;gt;
     &amp;lt;Column Name=\!"Resource\!" Operator=\!"Like\!" Value=\!"%a12%\!"/&amp;gt; 
    &amp;lt;/Where&amp;gt;
    &amp;lt;Projects&amp;gt;
      &amp;lt;Project Name=\!"abc\!"/&amp;gt;
    &amp;lt;/Projects&amp;gt;
  &amp;lt;/Data&amp;gt;
&amp;lt;/systemE&amp;gt;'
,@StartDateTime = '^farray[1]^'
,@EndDateTime   =' ^farray[2]^'");

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Jan 2020 18:21:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Open-SQL-database-user-input-Dates-Error-converting-data-type/m-p/240161#M47460</guid>
      <dc:creator>Botzal</dc:creator>
      <dc:date>2020-01-05T18:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL database - user input (Dates) -  Error converting data type varchar to datetime.</title>
      <link>https://community.jmp.com/t5/Discussions/Open-SQL-database-user-input-Dates-Error-converting-data-type/m-p/240225#M47470</link>
      <description>&lt;P&gt;I changed your window to be modal.&amp;nbsp; Otherwise the window displays and the SQL is attempted to be run all at once.&amp;nbsp; I'm not sure of the format needed for dates in SQL Server, so you may need to do a little research on that.&amp;nbsp; Copy the SQL statement that outputs to the log and try running it manually in a SQL server window.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nw = New Window( "test", &amp;lt;&amp;lt;modal(),
	H List Box(
		Text Box( "Start Date" ),
		a = Number Edit Box( 0 ),
		a &amp;lt;&amp;lt; set format( Format( "m/d/y" ) ),
		a &amp;lt;&amp;lt; set width( 12 ),
		a &amp;lt;&amp;lt; set( Today() ),
		Spacer Box( size( 10, 20 ) ),
		Text Box( "End Date" ),
		b = Number Edit Box( 0 ),
		b &amp;lt;&amp;lt; set format( Format( "m/d/y" ) ),
		b &amp;lt;&amp;lt; set width( 12 ),
		b &amp;lt;&amp;lt; set( Today() )
	),
	Spacer Box( size( 1, 20 ) ),    

	Button Box( "OK",
		start_date = Format( a &amp;lt;&amp;lt; get, "m/d/y" );
		end_date   = Format( b &amp;lt;&amp;lt; get, "m/d/y" );
	)
);

sql_statement = evalinsert("\[
EXEC dbo.listData @Criteria = '
&amp;lt;systemE&amp;gt;
  &amp;lt;Data Name="Alarm"&amp;gt;
    &amp;lt;Columns&amp;gt;
     &amp;lt;Column Name="Timestamp"/&amp;gt;  
    &amp;lt;/Columns&amp;gt;
    &amp;lt;Where&amp;gt;
     &amp;lt;Column Name="Resource" Operator="Like" Value="%a12%"/&amp;gt; 
    &amp;lt;/Where&amp;gt;
    &amp;lt;Projects&amp;gt;
      &amp;lt;Project Name="abc"/&amp;gt;
    &amp;lt;/Projects&amp;gt;
  &amp;lt;/Data&amp;gt;
&amp;lt;/systemE&amp;gt;'
,@StartDateTime = '^start_date^'
,@EndDateTime   = '^end_date^']\");

show(sql_statement);
// Uncomment the next line to run the command in SQL Server
//dta= Open database("DRIVER=SQL Server; SERVER=XXX;  Trusted_connection = Yes", sql_statement);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Other changes - if you want to use the ^xxx^ construct you need to enclose that in evalinsert().&amp;nbsp; I used the quoting escape characters \[ and ]\ so your SQL statement is a bit cleaner.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 16:37:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Open-SQL-database-user-input-Dates-Error-converting-data-type/m-p/240225#M47470</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-01-06T16:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL database - user input (Dates) -  Error converting data type varchar to datetime.</title>
      <link>https://community.jmp.com/t5/Discussions/Open-SQL-database-user-input-Dates-Error-converting-data-type/m-p/240280#M47479</link>
      <description>&lt;P&gt;For datetime I use the followig statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;t_now = "'" || Substitute(Format(today(),"yyyy-mm-ddThh:mm:ss"),"T"," ") || "'";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 07:30:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Open-SQL-database-user-input-Dates-Error-converting-data-type/m-p/240280#M47479</guid>
      <dc:creator>Mauro_Gerber</dc:creator>
      <dc:date>2020-01-07T07:30:02Z</dc:date>
    </item>
  </channel>
</rss>

