title: What is the best way to handle BOOLEAN values in Db2?
body: <p><strong>Database</strong></p>
  
  <p>Db2</p>
  
  <p><strong>Scenario</strong></p>
  
  <p>I have a column that needs to be true or false. I have found two sources that point to how to achieve this; however, when I bring them together I get an error.</p>
  
  <ol>
  <li><a href="https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0055394.html" rel="nofollow noreferrer">Boolean values</a></li>
  <li><a href="https://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.sql.ref.doc/doc/r0008478.html" rel="nofollow noreferrer">Casting between data types</a></li>
  </ol>
  
  <p><strong>Current Solution</strong></p>
  
  <pre><code>CREATE TABLE USERS
  (
     ID INT NOT NULL,
     .
     .
     .
     IS_LOCKED SMALLINT NOT NULL WITH DEFAULT 0,
     PRIMARY KEY(ID)
  );
  </code></pre>
  
  <p><code>SELECT U.ID, CAST(U.IS_LOCKED AS BOOLEAN) as IS_LOCKED FROM USERS U</code></p>
  
  <p>Error: <code>A value with data type "SYSIBM.SMALLINT" cannot be CAST to type "SYSIBM.BOOLEAN"</code></p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I use BOOLEANs in Db2?</p>