« Google Protocol Buffer faster than XML | Main | STORED PROCEDURES FOR NOVICE (BEGINNERS) IN SQL SERVER 2005 »

Handle null values in MySQL Query

- Jagadish. M


The following examples facilitate in handling null values in MySQL query itself instead of handling them in jsp pages.
                 
    
Syntax:
               
Select IFNULL (exp1,exp2) , IFNULL (exp1,exp2) from tableName
                IFNULL return exp1 if it is not null
                Else
                If exp1 is null then returns exp2
      

 Example 1:
Table_1

          In Interface it looks like this:

Interface_1

 

Select IFNULL(Name,’ Not Available ’),IFNULL(Address,’Not Available  ’),IFNULL(emailed,’Not Available’) from tableName

           Result:

Table_2

 

 

 

           In Interface it looks like this:

Interface_2

 

    Example 2:


          Select IFNULL(Name,’  ’),IFNULL(Address, ’),IFNULL(emailed,  ) from tableName

          Result:

 Table_3

         In Interface it looks like this:

 

Interface_3

 

(The author, Jagadish.M, is a Software Engineer at Binary Spectrum).

TrackBack

TrackBack URL for this entry:
http://binaryspectrum.com/geeksatwork-mt/mt-tb.fcgi/41

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)