<?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: can we use field name for comparison in case statement? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361320#M106720</link>
    <description>&lt;P&gt;Yes, you can use fields in case statements. Here is a simple example that proves it.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| fields - _time
| eval thresh = 3, value = 3
| eval result = case(thresh &amp;gt; value, "lower", thresh &amp;lt; value, "higher", thresh == value, "equal", 1==1, "0")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Without having your actual data, one suggestion I would make is replace &lt;CODE&gt;NULL&lt;/CODE&gt; with &lt;CODE&gt;NULL()&lt;/CODE&gt; in the case statement. Then change the following search to &lt;CODE&gt;| WHERE isnotnull(ty)&lt;/CODE&gt;. Maybe the fact that you are using &lt;CODE&gt;search&lt;/CODE&gt; against a table of field values and not &lt;CODE&gt;_raw&lt;/CODE&gt; is the issue.&lt;/P&gt;

&lt;P&gt;So the modified search would be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index= sourcetype= 
| stats values(OPEN_INT) as int by 
OPTION_TYP STRIKE_PR 
| appendcols [|search index= sourcetype= 
OPTION_TYP=XX | eval a1=CLOSE-(CLOSE*75)/10000|eval a2=CLOSE+(CLOSE*75)/10000| 
eval i2=CLOSE-(CLOSE*25)/1000 | eval o2=CLOSE+(CLOSE*25)/1000 |table a1 a2 i2 o2 CLOSE]
| eval ty=case(STRIKE_PR&amp;gt;=9839.46 AND STRIKE_PR&amp;lt;10016,"IN",STRIKE_PR&amp;gt;=10016 AND STRIKE_PR&amp;lt;10167,"AT"
,STRIKE_PR&amp;gt;=10167 AND STRIKE_PR&amp;lt;=10344,"OUT",1==1, NULL()) 
| where isnotnull(ty)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 10 Aug 2017 08:40:47 GMT</pubDate>
    <dc:creator>rjthibod</dc:creator>
    <dc:date>2017-08-10T08:40:47Z</dc:date>
    <item>
      <title>can we use field name for comparison in case statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361319#M106719</link>
      <description>&lt;P&gt;Hi Splunkers!&lt;/P&gt;

&lt;P&gt;I am try to evaluate few things by using query below-&lt;/P&gt;

&lt;P&gt;index=*  sourcetype=*  | stats  values(OPEN_INT) as int by &lt;BR /&gt;
OPTION_TYP STRIKE_PR | appendcols [|search index=* sourcetype=* &lt;BR /&gt;
  OPTION_TYP=XX |  eval a1=CLOSE-(CLOSE*75)/10000|eval a2=CLOSE+(CLOSE*75)/10000| &lt;BR /&gt;
eval i2=CLOSE-(CLOSE*25)/1000 |  eval o2=CLOSE+(CLOSE*25)/1000 |table a1 a2 i2 o2 CLOSE]|&lt;BR /&gt;
 eval ty=case(STRIKE_PR&amp;gt;=9839.46 AND STRIKE_PR&amp;lt;10016,"IN",STRIKE_PR&amp;gt;=10016 AND STRIKE_PR&amp;lt;10167,"AT"&lt;BR /&gt;
,STRIKE_PR&amp;gt;=10167 AND STRIKE_PR&amp;lt;=10344,"OUT",1==1, NULL) | search ty!=NULL |&lt;/P&gt;

&lt;P&gt;I need to use the values of fields a1 a2 i2 o2  in the case statement written above, such that my statement appears like-&lt;BR /&gt;
 eval ty=case(STRIKE_PR&amp;gt;=i2 AND STRIKE_PR=a1 AND STRIKE_PR=a2AND STRIKE_PR&amp;lt;=o2,"OUT",1==1, NULL) | search ty!=NULL |&lt;/P&gt;

&lt;P&gt;But splunk doesn't give me any results when i use fields name instead of the numeric value.&lt;/P&gt;

&lt;P&gt;Can someone figure out what the problem is?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:18:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361319#M106719</guid>
      <dc:creator>shivi_tcs</dc:creator>
      <dc:date>2020-09-29T15:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: can we use field name for comparison in case statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361320#M106720</link>
      <description>&lt;P&gt;Yes, you can use fields in case statements. Here is a simple example that proves it.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| fields - _time
| eval thresh = 3, value = 3
| eval result = case(thresh &amp;gt; value, "lower", thresh &amp;lt; value, "higher", thresh == value, "equal", 1==1, "0")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Without having your actual data, one suggestion I would make is replace &lt;CODE&gt;NULL&lt;/CODE&gt; with &lt;CODE&gt;NULL()&lt;/CODE&gt; in the case statement. Then change the following search to &lt;CODE&gt;| WHERE isnotnull(ty)&lt;/CODE&gt;. Maybe the fact that you are using &lt;CODE&gt;search&lt;/CODE&gt; against a table of field values and not &lt;CODE&gt;_raw&lt;/CODE&gt; is the issue.&lt;/P&gt;

&lt;P&gt;So the modified search would be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index= sourcetype= 
| stats values(OPEN_INT) as int by 
OPTION_TYP STRIKE_PR 
| appendcols [|search index= sourcetype= 
OPTION_TYP=XX | eval a1=CLOSE-(CLOSE*75)/10000|eval a2=CLOSE+(CLOSE*75)/10000| 
eval i2=CLOSE-(CLOSE*25)/1000 | eval o2=CLOSE+(CLOSE*25)/1000 |table a1 a2 i2 o2 CLOSE]
| eval ty=case(STRIKE_PR&amp;gt;=9839.46 AND STRIKE_PR&amp;lt;10016,"IN",STRIKE_PR&amp;gt;=10016 AND STRIKE_PR&amp;lt;10167,"AT"
,STRIKE_PR&amp;gt;=10167 AND STRIKE_PR&amp;lt;=10344,"OUT",1==1, NULL()) 
| where isnotnull(ty)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Aug 2017 08:40:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361320#M106720</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-08-10T08:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: can we use field name for comparison in case statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361321#M106721</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Thanks for replying.&lt;BR /&gt;
I got a part of solution from your answer!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 10:09:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361321#M106721</guid>
      <dc:creator>shivi_tcs</dc:creator>
      <dc:date>2017-08-10T10:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: can we use field name for comparison in case statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361322#M106722</link>
      <description>&lt;P&gt;Glad to hear you got it cleared up. Please award points or accept it as the answer if your issue is resolved.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 10:15:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/can-we-use-field-name-for-comparison-in-case-statement/m-p/361322#M106722</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-08-10T10:15:49Z</dc:date>
    </item>
  </channel>
</rss>

