SQL - CASE example

By kimot, 24 December, 2022

If you need to compare some fields in row in SELECT statement, you can do this with CASE expression :

SELECT A.data_queue_name, 
       A.data_queue_library,  
       A.current_messages, 
       B.current_messages, 
CASE 
    WHEN 
      A.current_messages = B.current_messages 
        THEN ' ' 
        ELSE '**diff**' 
END
FROM swtgemts1 A JOIN swtgemts2 B ON A.data_queue_name = B.data_queue_name;
HBCLNTICBSDAT00 
HBCLNTCTLICBSDAT00 
HBIAS1CTLICBSDAT00 
HBIAS2CTLICBSDAT00 
HBIAS3CTLICBSDAT00 
HBIAS4CTLICBSDAT00 
HBIAS5CTLICBSDAT00 
HBMULTCTLXICBSDAT41004100 
HBPX000ICBSDAT3024**diff**