Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB2 SQL Syntax for CASE Statement

Status
Not open for further replies.

ks01

MIS
Aug 11, 2002
110
US
Hello ...

I'm looking for some advice on how to handle the following task.

I’m trying to get a value to display if the original value is NULL. Here is my SQL:

Code:
      CASE (B.USR_R_NM)                                              
           WHEN X'60'                                                
           THEN '***USER ' || RTRIM(A.USER_ADD_ID) || ' DELETED***'
           ELSE B.USR_R_NM                                           
      END AS USER_NM,

Here is the value for this 27-byte field:
Code:
-                          
644444444444444444444444444
000000000000000000000000000

I’ve also tried

Code:
      CASE (B.USR_R_NM)                                              
           WHEN NULL                                                 
           THEN '***USER ' || RTRIM(A.USER_ADD_ID) || ' DELETED***'
           ELSE B.USR_R_NM                                           
      END AS USER_NM,

However neither option seems to work successfully for me.

I would appreciate any feedback.

Thanks in advance!
 
Hi everyone ...

Just an update, I found the following seems to work and uses the CASE statement:

Code:
CASE WHEN B.USR_R_NM IS NULL                                     
     THEN '*** USER ' || RTRIM(A.USER_ADD_ID) || ' DELETED ***'
     ELSE B.USR_R_NM                                             
 END AS USER_NM,

Thank you again for the suggestions!
 
You do not need a case whatsoever when you learn what Coalesce does..

Ties Blom

 
I couldn't figure out what coalesce did.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top