<?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 to get the field names based on the case statement conditions? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161754#M45710</link>
    <description>&lt;P&gt;I have to point out that there are some other problems with your search. I have shown it below so that I can refer to it line-by-line&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="pivotsource" OR sourcetype="vodplayerrors_animation" 
| stats count AS tnow 
| eval tnow = now() 
| convert ctime(tnow) 
| eval n= substr(tnow,15,15) 
| eval m= substr(n,0,2)
| eval switcherValue=case(m=55,voderrorcode,m=56,status) 
| stats count by switcherValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In line 2, the &lt;CODE&gt;stats&lt;/CODE&gt; command is unnecessary, because you overwrite the value of &lt;CODE&gt;tnow&lt;/CODE&gt; in line 3 with the time that this search began. Did you really mean to use &lt;CODE&gt;now()&lt;/CODE&gt;? I would have expected to use &lt;CODE&gt;_time&lt;/CODE&gt;, but then I don't understand the condition you are testing. Finally, you seem to be manipulating the time to pick off certain characters in lines 3-5, but this seems like a hard way to do it.&lt;/P&gt;

&lt;P&gt;Why not do this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="pivotsource" OR sourcetype="vodplayerrors_animation" 
| eval m = strftime(now(),"%M")
| eval switcherValue=case(m==55,voderrorcode,
     m==56,status,
     1==1,null()) 
| stats count by switcherValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was too lazy to figure out what all the &lt;CODE&gt;substr&lt;/CODE&gt; was about, so i just set &lt;CODE&gt;m&lt;/CODE&gt; to the minutes portion of the time. If you wanted some other part of the time, look here for the codes: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Commontimeformatvariables"&gt;Common Time Format Variables&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
Also, note that I added a third option to the &lt;CODE&gt;case&lt;/CODE&gt; function - what if &lt;CODE&gt;m&lt;/CODE&gt; is something other than 55 or 56? In that case, I set &lt;CODE&gt;switcherValue&lt;/CODE&gt; to null, but you could set it to something else.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Dec 2013 07:45:56 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2013-12-03T07:45:56Z</dc:date>
    <item>
      <title>how to get the field names based on the case statement conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161751#M45707</link>
      <description>&lt;P&gt;This is my query&lt;/P&gt;

&lt;P&gt;sourcetype="pivotsource" OR sourcetype="vodplayerrors_animation" | stats count AS tnow | eval tnow = now() | &lt;BR /&gt;
convert ctime(tnow) | eval n=substr(tnow,15,15) |eval m=substr(n,0,2)| eval switcherValue=case(m=55,&lt;STRONG&gt;voderrorcode&lt;/STRONG&gt;,m=56,&lt;STRONG&gt;status&lt;/STRONG&gt;) | stats count by switcherValue&lt;/P&gt;

&lt;P&gt;I have to get the field name based on the m value in the case.Even though Iam not giving the quotes case statement is trating as string,because of this iam not getting switchervalue as filedname.&lt;/P&gt;

&lt;P&gt;Please advise me how to get the fieldname from case statement instead a string.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 10:22:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161751#M45707</guid>
      <dc:creator>lahariveerlapat</dc:creator>
      <dc:date>2013-12-02T10:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the field names based on the case statement conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161752#M45708</link>
      <description>&lt;P&gt;in the above search i kept m values in quotes | eval switcherValue=case(m="55",voderrorcode,m="56",status) | stats count by switcherValue&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 10:24:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161752#M45708</guid>
      <dc:creator>lahariveerlapat</dc:creator>
      <dc:date>2013-12-02T10:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the field names based on the case statement conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161753#M45709</link>
      <description>&lt;P&gt;Try following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="pivotsource" OR sourcetype="vodplayerrors_animation" | stats count AS tnow | eval tnow = now() | 
convert ctime(tnow) | eval n=substr(tnow,15,15) |eval m=substr(n,0,2)| eval switcherValue=case(m=55,voderrorcode,m=56,status) | eval sno=1| chart count over sno by switcherValue | fields - sno
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Dec 2013 15:03:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161753#M45709</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2013-12-02T15:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the field names based on the case statement conditions?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161754#M45710</link>
      <description>&lt;P&gt;I have to point out that there are some other problems with your search. I have shown it below so that I can refer to it line-by-line&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="pivotsource" OR sourcetype="vodplayerrors_animation" 
| stats count AS tnow 
| eval tnow = now() 
| convert ctime(tnow) 
| eval n= substr(tnow,15,15) 
| eval m= substr(n,0,2)
| eval switcherValue=case(m=55,voderrorcode,m=56,status) 
| stats count by switcherValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In line 2, the &lt;CODE&gt;stats&lt;/CODE&gt; command is unnecessary, because you overwrite the value of &lt;CODE&gt;tnow&lt;/CODE&gt; in line 3 with the time that this search began. Did you really mean to use &lt;CODE&gt;now()&lt;/CODE&gt;? I would have expected to use &lt;CODE&gt;_time&lt;/CODE&gt;, but then I don't understand the condition you are testing. Finally, you seem to be manipulating the time to pick off certain characters in lines 3-5, but this seems like a hard way to do it.&lt;/P&gt;

&lt;P&gt;Why not do this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="pivotsource" OR sourcetype="vodplayerrors_animation" 
| eval m = strftime(now(),"%M")
| eval switcherValue=case(m==55,voderrorcode,
     m==56,status,
     1==1,null()) 
| stats count by switcherValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was too lazy to figure out what all the &lt;CODE&gt;substr&lt;/CODE&gt; was about, so i just set &lt;CODE&gt;m&lt;/CODE&gt; to the minutes portion of the time. If you wanted some other part of the time, look here for the codes: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Commontimeformatvariables"&gt;Common Time Format Variables&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
Also, note that I added a third option to the &lt;CODE&gt;case&lt;/CODE&gt; function - what if &lt;CODE&gt;m&lt;/CODE&gt; is something other than 55 or 56? In that case, I set &lt;CODE&gt;switcherValue&lt;/CODE&gt; to null, but you could set it to something else.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2013 07:45:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-field-names-based-on-the-case-statement/m-p/161754#M45710</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-12-03T07:45:56Z</dc:date>
    </item>
  </channel>
</rss>

