<?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: variable passed into subsequent search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556226#M157943</link>
    <description>&lt;P&gt;Yes, that can be done.&amp;nbsp; Run the "first" search in a subsearch (inside square brackets) so it runs first.&amp;nbsp; The results of the subsearch will become part of the main search, which runs after the subsearch completes.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| dbxquery query="SELECT t.id, t.description FROM 'database_name'.'table_name' t WHERE t.id IN [&amp;lt;first search that returns a list of ids&amp;gt; | stats values(id) as temp_ids | eval ids_list=mvjoin(temp_ids, ",") | return $temp_ids]" connection="connection_name"&lt;/LI-CODE&gt;&lt;P&gt;I've not used a subsearch within dbquery so YMMV.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jun 2021 18:55:02 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2021-06-17T18:55:02Z</dc:date>
    <item>
      <title>variable passed into subsequent search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556191#M157934</link>
      <description>&lt;P&gt;Is it possible to use the value derived from one search and pass it to another search?&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have a search and create a comma separated list of values ids_list:&lt;/P&gt;&lt;P&gt;&amp;lt;first search&amp;gt; | stats values(id) as temp_ids | eval ids_list=mvjoin(temp_ids, ",")&lt;/P&gt;&lt;P&gt;I'd like to use ids_list in a subsequent search. For example:&lt;/P&gt;&lt;P&gt;&amp;lt;first search that returns a list of ids&amp;gt; | stats values(id) as temp_ids | eval ids_list=mvjoin(temp_ids, ",")&amp;nbsp;&lt;SPAN&gt;| search&amp;nbsp; [ | dbxquery query="SELECT t.id, t.description FROM 'database_name'.'table_name' t&amp;nbsp;&lt;/SPAN&gt;WHERE t.id IN (ids_list)" connection="connection_name"]&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 15:00:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556191#M157934</guid>
      <dc:creator>rberman</dc:creator>
      <dc:date>2021-06-17T15:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: variable passed into subsequent search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556226#M157943</link>
      <description>&lt;P&gt;Yes, that can be done.&amp;nbsp; Run the "first" search in a subsearch (inside square brackets) so it runs first.&amp;nbsp; The results of the subsearch will become part of the main search, which runs after the subsearch completes.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| dbxquery query="SELECT t.id, t.description FROM 'database_name'.'table_name' t WHERE t.id IN [&amp;lt;first search that returns a list of ids&amp;gt; | stats values(id) as temp_ids | eval ids_list=mvjoin(temp_ids, ",") | return $temp_ids]" connection="connection_name"&lt;/LI-CODE&gt;&lt;P&gt;I've not used a subsearch within dbquery so YMMV.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 18:55:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556226#M157943</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-06-17T18:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: variable passed into subsequent search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556534#M158059</link>
      <description>&lt;P&gt;Thank you so much for answering me &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;! I tried your suggestion and the subsearch doesn't run because it is inside the quotes of the query parameter as in&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| dbxquery query="some select text [&amp;lt;your suggested subquery&amp;gt;]" connection="connection_name"&lt;/LI-CODE&gt;&lt;P&gt;Is there a way to get around the quotes?&amp;nbsp; I have been trying&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| dbxquery query="SELECT t.id, t.description FROM 'database_name'.'table_name' t WHERE t.id IN(?)" connection="connection_name" params=[&amp;lt;first search that returns a list of ids&amp;gt; | stats values(id) as temp_ids | eval ids_list=mvjoin(temp_ids, ",") | return $temp_ids]&lt;/LI-CODE&gt;&lt;P&gt;but that hasn't worked for me.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 14:43:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556534#M158059</guid>
      <dc:creator>rberman</dc:creator>
      <dc:date>2021-06-21T14:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: variable passed into subsequent search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556544#M158064</link>
      <description>&lt;P&gt;I was afraid the subsearch wouldn't work in dbquery.&amp;nbsp; Sorry, but I don't have a workaround.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:27:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556544#M158064</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-06-21T15:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: variable passed into subsequent search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556562#M158069</link>
      <description>&lt;P&gt;I did some searching around and was able to get it to work via the answer on this thread:&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Splunk-dbxquery-to-call-stored-procedure-with-subsearch-to/m-p/438337" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Splunk-dbxquery-to-call-stored-procedure-with-subsearch-to/m-p/438337&lt;/A&gt;&lt;/P&gt;&lt;P&gt;my resulting query is:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;first search&amp;gt; | stats values(id) as temp_ids | eval ids_list=mvjoin(temp_ids, ",") |
map search="| dbxquery connection=\"connection_name\" query=\"SELECT t.id, t.description FROM database_name.table_name t WHERE t.id IN ($ids_list$)\""&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 21 Jun 2021 16:56:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/variable-passed-into-subsequent-search/m-p/556562#M158069</guid>
      <dc:creator>rberman</dc:creator>
      <dc:date>2021-06-21T16:56:07Z</dc:date>
    </item>
  </channel>
</rss>

