Note that there are some explanatory texts on larger screens.

plurals
  1. PODB2 - handling columns defined as null
    primarykey
    data
    text
    <p>Let's say you have three textboxes that you can use to search for data. Each textbox will correspond to a column on the DB2 table. The search string you enter will be inserted into the where clause. For example, you have First-Name, Last-Name, and Phone Number. If you don't enter data into a particular textbox, I default its value in the where clause to '_', the wildcard character to select everything. Also, lets say Phone Number is defined as NULL on the table.</p> <p>Cursor1 will be used if the user has entered a Phone number to search for. So the where clause will look something like this:</p> <p>Where FIRST_NAME like :firstname AND LAST_NAME like :lastname AND PHONE_NBR like :number</p> <p>This works when data is entered for phone number. But if a search is done for First Name only, the cursor returns partial or no results because the :number host variable will be populated with the "_' wildcard. PHONE_NBR like '_' will only return the rows that have a real value. If there is a null for PHONE_NBR on a row that matches the First Name you searched for, that row won't show up. So I created a second cursor.</p> <p>Cursor2 will be used if the user HAS NOT entered a Phone number to search for. The Where clause looks something like this.</p> <p>Where FIRST_NAME like :firstname AND LAST_NAME like :lastname AND (PHONE_NBR like :number OR PHONE_NBR IS NULL)</p> <p>So again, if a search was done for a first name only, and some values in PHONE_NBR have data, some are null, EVERYTHING that matches the first name that is searched for will show in the results - which is good. For the rows with values in PHONE_NBR, PHONE_NBR like '_' will get those. For the rows with null in PHONE_NBR, PHONE_NBR IS NULL will get those.</p> <p><em><strong>This is a minor yet necessary difference. Because of this minor difference, I would like to combine these two cursors into one. How can that be done to achieve the same results?</em></strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload