title: Use an SQL result variable in a Mule flow
body: <p>I got a Mule flow with 2 queries.
  The first simply validates if a username is duplicated.</p>
  <p>Does something like this:</p>
  <pre><code>SELECT count(*) AS TOTAL FROM user_tests WHERE username = #[json:username] AND test_message_title = #[json:test_message_title]
  </code></pre>
  <p>The second one does an INSERT if TOTAL = 0.</p>
  <p>Now, i want to use the variable &quot;TOTAL&quot; in a choice inside the same flow.
  How do i do it?</p>
  <p>Tried #[TOTAL=0], tried #[variable:TOTAL=0], and many others but couldn't make it work.</p>
  <p>EDITED: I made a java component that retrieve the &quot;0&quot; or whatever number from the payload.
  How do i make the choice expression to compare it?</p>
  <p>Tried using Integer.valueOf(message.payload) = 0 in the choice expression but i get an InvalidExpressionException.</p>
  <p>This is my entire flow:</p>
  <pre><code>&lt;flow name=&quot;ADMIN_INSERT_TEST_FILE&quot; doc:name=&quot;ADMIN_INSERT_TEST_FILE&quot;&gt;
      &lt;ajax:servlet-inbound-endpoint channel=&quot;/admin/save_test_message&quot; responseTimeout=&quot;10000&quot; doc:name=&quot;Ajax&quot;/&gt;
      &lt;set-variable variableName=&quot;#['saved_payload']&quot; value=&quot;#[payload]&quot; doc:name=&quot;Save original payload&quot;/&gt;
      &lt;jdbc:outbound-endpoint exchange-pattern=&quot;request-response&quot; queryKey=&quot;validate_test_name&quot; queryTimeout=&quot;-1&quot; connector-ref=&quot;ExtendedRoutingConnector&quot; doc:name=&quot;validate duplicated test name&quot;&gt;
          &lt;jdbc:query key=&quot;validate_test_name&quot; value=&quot;SELECT count(*) AS TOTAL FROM user_tests WHERE username = #[json:username] AND test_message_title = #[json:test_message_title]&quot;/&gt;
      &lt;/jdbc:outbound-endpoint&gt;
      &lt;logger message=&quot;#[message.payload[0].TOTAL]&quot; level=&quot;INFO&quot; category=&quot;Total&quot; doc:name=&quot;Logger&quot;/&gt;
      &lt;choice doc:name=&quot;Choice&quot;&gt;
          &lt;when expression=&quot;#[message.payload[0].TOTAL == 0]&quot;&gt;
              &lt;processor-chain&gt;
                  &lt;set-payload value=&quot;#[variable:saved_payload]&quot; doc:name=&quot;Save Payload&quot;/&gt;
                  &lt;jdbc:outbound-endpoint exchange-pattern=&quot;request-response&quot; queryKey=&quot;insert_user_test_message&quot; queryTimeout=&quot;-1&quot; connector-ref=&quot;ExtendedRoutingConnector&quot; doc:name=&quot;insert user test message&quot;&gt;
                      &lt;jdbc:query key=&quot;insert_user_test_message&quot; value=&quot;INSERT INTO user_tests (username, test_message_title, user_test_message) VALUES (#[json:username], #[json:test_message_title], #[json:message])&quot;/&gt;
                  &lt;/jdbc:outbound-endpoint&gt;
              &lt;/processor-chain&gt;
          &lt;/when&gt;
          &lt;otherwise&gt;
              &lt;processor-chain&gt;
                  &lt;logger message=&quot;Name #[json:test_message_title] already exists&quot; level=&quot;INFO&quot; doc:name=&quot;Logger&quot;/&gt;
              &lt;/processor-chain&gt;
          &lt;/otherwise&gt;
      &lt;/choice&gt;
  &lt;/flow&gt;
  </code></pre>