<?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: How can I add a date range to dbquery based on search dates on interface? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288483#M55135</link>
    <description>&lt;P&gt;For your time range what is your input type is it &lt;CODE&gt;text&lt;/CODE&gt; or &lt;CODE&gt;time&lt;/CODE&gt;&lt;BR /&gt;
also have you checked @brunton2 answer&lt;BR /&gt;
here &lt;CODE&gt;input type="time"&lt;/CODE&gt; is used and then used $form.et$, $form.lt$ in dbquery like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery mydb "SELECT timestamp_column, other_column1, other_column2 FROM mytable | AND (TIME_STAMP &amp;gt;= TO_DATE('$form.et$', 'YYYY-MM-DD HH24:MI:SS') AND TIME_STAMP &amp;lt;= TO_DATE('$form.lt$', 'YYYY-MM-DD HH24:MI:SS'))"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;currently I am unable to test these query in my local...&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2018 04:57:58 GMT</pubDate>
    <dc:creator>493669</dc:creator>
    <dc:date>2018-02-16T04:57:58Z</dc:date>
    <item>
      <title>How can I add a date range to dbquery based on search dates on interface?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288480#M55132</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4392iB3412850382D4F90/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Hello&lt;BR /&gt;
Can someone please tell me how to add a date range to dbquery.  I wish the time range of the image (text boxes in the edit Search, Reports, and alerts) as shown in the image.&lt;/P&gt;

&lt;P&gt;I assume this is $job.earliestTime$ and $job.latestTime$&lt;/P&gt;

&lt;P&gt;What I want is something like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery MyDatabase "SELECT DISTINCT TOP 10 * FROM V_MyView MyDate BETWEEN " + $job.earliestTime$ + " and "  + $job.latestTime$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically, return everything in a date range as my view is too big and I only need the range that is selected.&lt;/P&gt;

&lt;P&gt;But I keep getting the error command="dbquery", A database error occurred: Invalid SQL statement or JDBC escape, terminating ''' not found.&lt;/P&gt;

&lt;P&gt;I also tried things like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery MyDatabase "SELECT DISTINCT TOP 10 * FROM V_MyView MyDate BETWEEN " . $job.earliestTime$ . " and " . $job.latestTime$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;dbquery must be the first command so I cannot use anything like eval &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;
I'm sure I cant be the first person to have this issue.&lt;BR /&gt;
Please help.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 02:47:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288480#M55132</guid>
      <dc:creator>alexsmirnoff</dc:creator>
      <dc:date>2018-02-16T02:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a date range to dbquery based on search dates on interface?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288481#M55133</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Try @sowings or @ziegfried  answer from &lt;A href="https://answers.splunk.com/answers/75999/splunk-db-connect-dbquery-inline-search-and-time-filtering-not-working.html"&gt;https://answers.splunk.com/answers/75999/splunk-db-connect-dbquery-inline-search-and-time-filtering-not-working.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 03:14:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288481#M55133</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-16T03:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a date range to dbquery based on search dates on interface?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288482#M55134</link>
      <description>&lt;P&gt;The only thing close to what I ased is the last example on this link.  It did not work when I pumped in a basic sql query.  I tried this (except with a real view):&lt;/P&gt;

&lt;P&gt;|  dbquery MyDatabase  [ eval query= "SELECT DISTINCT TOP 10 * FROM V_MyView "]&lt;/P&gt;

&lt;P&gt;This did not work at all &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  All I got was SPLUNK errors.&lt;/P&gt;

&lt;P&gt;Can please direct me to something that is a simple complete working example.  Anthing that can use a eval and joins 2 strings.&lt;/P&gt;

&lt;P&gt;I saw this page ages ago, tried thier example and they didnt work.  My real query has averages, counts and calculations, so it cannot be a two set query.  There are millions of rows of data in my query (big data).&lt;/P&gt;

&lt;P&gt;The second part of the question is very simply.  I should not be given a URL.  What are the variable names for Earliest and Latest (based on the image).  &lt;/P&gt;

&lt;P&gt;Are they &lt;BR /&gt;
 $job.earliestTime$ and $job.latestTime$&lt;/P&gt;

&lt;P&gt;if not...  what are they?&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;I  would have thought this would be the first example on the user guide on how to use dbquery.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 04:00:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288482#M55134</guid>
      <dc:creator>alexsmirnoff</dc:creator>
      <dc:date>2018-02-16T04:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a date range to dbquery based on search dates on interface?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288483#M55135</link>
      <description>&lt;P&gt;For your time range what is your input type is it &lt;CODE&gt;text&lt;/CODE&gt; or &lt;CODE&gt;time&lt;/CODE&gt;&lt;BR /&gt;
also have you checked @brunton2 answer&lt;BR /&gt;
here &lt;CODE&gt;input type="time"&lt;/CODE&gt; is used and then used $form.et$, $form.lt$ in dbquery like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery mydb "SELECT timestamp_column, other_column1, other_column2 FROM mytable | AND (TIME_STAMP &amp;gt;= TO_DATE('$form.et$', 'YYYY-MM-DD HH24:MI:SS') AND TIME_STAMP &amp;lt;= TO_DATE('$form.lt$', 'YYYY-MM-DD HH24:MI:SS'))"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;currently I am unable to test these query in my local...&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 04:57:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288483#M55135</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-16T04:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a date range to dbquery based on search dates on interface?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288484#M55136</link>
      <description>&lt;P&gt;This is an ugly search, but you could try something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery MyDatabase 
    [| makeresults 
    | addinfo 
    | eval info_max_time=if(info_max_time="+Infinity", now(), info_max_time) 
    | eval earliest=strftime(info_min_time, "%Y-%m-%d %H:%M:%S"), latest=strftime(info_max_time, "%Y-%m-%d %H:%M:%S") 
    | eval search="\"SELECT DISTINCT TOP 10 FROM V_MyView MyDate BETWEEN ".earliest." and ".latest."\""]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The subsearch creates a dummy event, adds the search info to the event (&lt;CODE&gt;addinfo&lt;/CODE&gt;), calculates string representations for earliest/latest, and crafts a string for the query using those stringified dates.  That query string is named &lt;CODE&gt;search&lt;/CODE&gt;, which causes the subsearch to place the contents of the &lt;CODE&gt;search&lt;/CODE&gt; field directly into your search, resulting in a search that looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery MyDatabase "SELECT DISTINCT TOP 10 FROM V_MyView MyDate BETWEEN 1970-01-01 00:00:00 and 2018-02-15 18:58:09"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Feb 2018 15:03:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-add-a-date-range-to-dbquery-based-on-search-dates-on/m-p/288484#M55136</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-16T15:03:06Z</dc:date>
    </item>
  </channel>
</rss>

