title: Capture db2 sql results in shell script
body: <p>I have a shell script which will connect to database and get the results. My script is like</p>
  
  <pre><code>#!/bin/bash
  getResults()
  {
      db2 "connect to ${1} user ${2} using ${3}"
      db2 "set schema ${4}"
      status=`db2 -x "select status from results where id=1"`
      echo $status
  }
  #MAIN STARS HERE
  getResults dbname foo bar test
  </code></pre>
  
  <p>Now I wanted to get multiple columns from results tables using </p>
  
  <pre><code>select status,timestamp from results where id=1
  </code></pre>
  
  <p>How can I run the above query and capture both status and timestamp into two different shell variables using single query instead of running 2 differnt queries like</p>
  
  <pre><code>#!/bin/bash
  getResults()
  {
      db2 "connect to ${1} user ${2} using ${3}"
      db2 "set schema ${4}"
      status=`db2 -x "select status from results where id=1"`
      echo $status
       timestamp=`db2 -x "select timestamp from results where id=1"`
      echo $timestamp
  
  }
  #MAIN STARS HERE
  getResults dbname foo bar test
  </code></pre>
  
  <p>My results table is like:</p>
  
  <pre><code>create table (id number, status char(1), timestamp datetime);
  </code></pre>
  
  <p>And data is like</p>
  
  <pre><code>1 P &lt;some ts&gt;
  2 F &lt;some ts&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>