<?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: Selecting all rows in a data table where date/time is between two values in another table in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/887991#M105018</link>
    <description>&lt;P&gt;Here is how I would handle this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Clear Symbols();
// Reference both tables
timeEvents = Data Table( "Events" );
timeHVAC = Data Table( "HVAC" );

For( i = 1, i &amp;lt;= N Rows( timeEvents ), i++,
	Try(
		timeHVAC:Matched[timeHVAC &amp;lt;&amp;lt; get rows where(
			timeHVAC:Round_date &amp;gt;= timeEvents:Round_when_started[i] &amp;amp; timeHVAC
			:Round_date &amp;lt;= timeEvents:Round_when_ended[i]
		)] = 1
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1752856513298.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78539iD8960CBE8E763802/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1752856513298.png" alt="txnelson_0-1752856513298.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Jul 2025 16:35:24 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2025-07-18T16:35:24Z</dc:date>
    <item>
      <title>Selecting all rows in a data table where date/time is between two values in another table</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/887979#M105017</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have two data tables named, HVAC and Events.&amp;nbsp; I want to match date/times in HVAC based on start time and end times of the Events table and mark the matching rows in HVAC table with 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have script that runs but does not populate the "Matched" column and I am not quite sure why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here (1);
Clear Symbols();
// Reference both tables
timeEvents = DataTable("Events");
timeHVAC = DataTable("HVAC");

// Get column references
startCol = timeEvents:Round_when_started;
endCol = timeEvents:Round_when_ended;
timeHVACCol = timeHVAC:Round_date;
matchedCol = timeHVAC:Matched;
Batch Interactive( 1 );

// Loop through timeEvents and tag matches
For(i = 1, i &amp;lt;= N Rows(timeEvents), i++,
    startTime = startCol[i];
    endTime = endCol[i];

    // Loop through HVAC and tag matching rows
    For(j = 1, j &amp;lt;= N Rows(timeHVAC), j++,
        eventTime = timeHVACCol[j];
        If(eventTime &amp;gt;= startTime &amp;amp; eventTime &amp;lt;= endTime,
            matchedCol[j] = 1;
        );
    );
);
Batch Interactive( 0 );

// Notify user
New Window("Script Completed",
    Text Box("Lucy, I'm home!")
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jul 2025 15:24:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/887979#M105017</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2025-07-18T15:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all rows in a data table where date/time is between two values in another table</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/887991#M105018</link>
      <description>&lt;P&gt;Here is how I would handle this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Clear Symbols();
// Reference both tables
timeEvents = Data Table( "Events" );
timeHVAC = Data Table( "HVAC" );

For( i = 1, i &amp;lt;= N Rows( timeEvents ), i++,
	Try(
		timeHVAC:Matched[timeHVAC &amp;lt;&amp;lt; get rows where(
			timeHVAC:Round_date &amp;gt;= timeEvents:Round_when_started[i] &amp;amp; timeHVAC
			:Round_date &amp;lt;= timeEvents:Round_when_ended[i]
		)] = 1
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1752856513298.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78539iD8960CBE8E763802/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1752856513298.png" alt="txnelson_0-1752856513298.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 16:35:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/887991#M105018</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2025-07-18T16:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all rows in a data table where date/time is between two values in another table</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888003#M105021</link>
      <description>&lt;P&gt;If this is how your data looks like (even hours) and the matches are defined like in your script, you should be able to do this with double join/update. Add Matched column to your Events table&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_3-1752857305704.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78543i157863E1AE331334/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_3-1752857305704.png" alt="jthi_3-1752857305704.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then first join using Round_date and Round_when_started&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1752857206450.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78540i953D36DA5DC4EA6F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1752857206450.png" alt="jthi_0-1752857206450.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1752857238440.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78541i1B27C4F82A7217F7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1752857238440.png" alt="jthi_1-1752857238440.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Then for second join use Round_date and round_when_ended.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1752857295210.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78542i847FD0E90B476EA1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_2-1752857295210.png" alt="jthi_2-1752857295210.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And of course you can use something like Jim did demonstrate.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 16:50:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888003#M105021</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-07-18T16:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all rows in a data table where date/time is between two values in another table</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888034#M105022</link>
      <description>&lt;P&gt;Thank you Jim.&lt;/P&gt;
&lt;P&gt;Worked!&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 17:46:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888034#M105022</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2025-07-18T17:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all rows in a data table where date/time is between two values in another table</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888035#M105023</link>
      <description>&lt;P&gt;Hi Jarmo,&lt;/P&gt;
&lt;P&gt;Sorry I should have posted that I am using JMP and not JMP Pro.&lt;/P&gt;
&lt;P&gt;It never crossed my mind to double join and may try that in Query Builder.&lt;/P&gt;
&lt;P&gt;Cheers!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 17:49:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888035#M105023</guid>
      <dc:creator>Onjai</dc:creator>
      <dc:date>2025-07-18T17:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting all rows in a data table where date/time is between two values in another table</title>
      <link>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888057#M105024</link>
      <description>&lt;P&gt;I think you shouldn't need JMP Pro for what I did. I just used Tables &amp;gt; Update (should be available with standard JMP) twice but you could also do it with a single query using Query Builder&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1752865548113.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78548iDD75B9A24935F63E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1752865548113.png" alt="jthi_0-1752865548113.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I added one calculated column&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1752865580376.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/78549i5A18D39BAE19BD38/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1752865580376.png" alt="jthi_1-1752865580376.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;P&gt;SQL query is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;SELECT t1.Round_date, t1."Building pressure", t1."Plant Temp", t1."Zone Humdity", 
	t1."outside air temp", t3.Round_when_ended IS NOT NULL  OR  t2.Round_when_started IS NOT NULL AS Calc1, t3.Round_when_ended IS NOT NULL  OR  t2.Round_when_started IS NOT NULL AS "Calc1 2" 
FROM HVAC  t1 
	LEFT OUTER JOIN Events t3 
		ON  ( t1.Round_date = t3.Round_when_ended )  
	LEFT OUTER JOIN Events t2 
		ON  ( t1.Round_date = t2.Round_when_started );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And JMP's query builder script is something like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New SQL Query(
	Version(130),
	Connection("JMP"),
	JMP Tables(["Events" =&amp;gt; "\C:\Users\jarmo\Downloads\Events.jmp", "HVAC" =&amp;gt; "\C:\Users\jarmo\Downloads\HVAC.jmp"]),
	QueryName("SQLQuery1"),
	Select(
		Column("Round_date", "t1", Numeric Format("m/d/y h:m:s", "0", "NO", "")),
		Column("Building pressure", "t1", Numeric Format("Fixed Dec", "0", "NO", "")),
		Column("Plant Temp", "t1", Numeric Format("Fixed Dec", "0", "NO", "")),
		Column("Zone Humdity", "t1", Numeric Format("Fixed Dec", "0", "NO", "")),
		Column("outside air temp", "t1", Numeric Format("Fixed Dec", "0", "NO", "")),
		ExprLookup("Calc1", JMP Name("Calc1"))
	),
	From(
		Table("HVAC", Alias("t1")),
		Table(
			"Events",
			Alias("t3"),
			Join(
				Type(Left Outer),
				EQ(
					Column("Round_date", "t1", Numeric Format("m/d/y h:m:s", "0", "NO", "")),
					Column("Round_when_ended", "t3", Numeric Format("y/m/d h:m:s", "0", "NO", ""))
				)
			)
		),
		Table(
			"Events",
			Alias("t2"),
			Join(
				Type(Left Outer),
				EQ(
					Column("Round_date", "t1", Numeric Format("m/d/y h:m:s", "0", "NO", "")),
					Column("Round_when_started", "t2", Numeric Format("y/m/d h:m:s", "0", "NO", ""))
				)
			)
		),
		Expression("t3.Round_when_ended IS NOT NULL  OR  t2.Round_when_started IS NOT NULL", Alias("Calc1"))
	),
	Where(Custom("", UI(Custom(Base("Continuous")))))
) &amp;lt;&amp;lt; Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 19:09:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Selecting-all-rows-in-a-data-table-where-date-time-is-between/m-p/888057#M105024</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-07-18T19:09:08Z</dc:date>
    </item>
  </channel>
</rss>

