title: SQL query to drop null/blank values from Database (DB2 and Teradata specific)
body: <p>I am developing an application which uses external datasources. My Application supports multiple databases(viz. MySQl,MsSQl,Teradata, Oracle, DB2 etc.). When i create a datasource, I allow user to assign a primary key(pk) to the datasource. Now, <strong>I am not checking if the user selected column is primary key or not in actual database</strong>. I just want that, while retrieving data from database, the records which have null/blank value in <em>user selected primary key</em> should get dropped. I have created a filter supporting all other databases except for DB2 and Teradata.</p>
  
  <p>Sample Query for other databases:</p>
  
  <ol>
  <li><code>Select * from MY_TABLE where PK_COLUMN IS NOT NULL and PK_COLUMN !='';</code></li>
  <li><code>Select * from MY_TABLE where PK_COLUMN IS NOT NULL AND cast(PK_COLUMN as varchar) !=''</code></li>
  </ol>
  
  <p>DB2 and Teradata:</p>
  
  <p>The <code>PK_COLUMN !=''</code> and <code>cast(PK_COLUMN as varchar) !=''</code> conditions gives error for int datatype in DB2 and teradata because: 
   - column with int type cannot be gven the above mentioned conditions and also we cannot cast the int type columns to varchar directly in DB2 and Teradata.</p>
  
  <p>I want to create a query to drop null/blank value from the database provided table name and user pk column name as string. (I do not know the pk_column_type while creating the query so the query should be uniform to support all datatypes)</p>
  
  <p><strong>NOTE: The <code>pk</code> here is not actual pk, it is just a dummy pk assigned by my application user. So this can be a normal column and thus can have null/blank values.</strong></p>
  
  <p>I have created a query as:</p>
  
  <p><code>Select * from MY_TABLE where PK_COLUMN IS NOT NULL AND cast(cast(PK_COLUMN as char) as varchar) !=''</code></p>
  
  <p>My Question:</p>
  
  <ol>
  <li>Will this solution(double casting) support all datatypes in DB2 and Teradata?</li>
  <li>If not, can I come up with a better solution?</li>
  </ol>