SQL - Decode / TO_CHAR / Case When

TO_CHAR

SELECT TO_CHAR(DATE_OF_CONTACT, 'dd-MM-yyyy') as DATE_OF_CONTACT, LOG_ID

  FROM ROSS_LOG_INFO

 WHERE LOG_STATUS != 4

   AND LOG_TYPE = '4'

   AND CUSTOMER_PROSPECT_ID = 'xx';

Decode 

SELECT a.log_id,

       a.acc_no,

       a.customer_prospect_name,

       b.agt_code,

       decode(a.log_type,              1,              

             'Pre-Contact',            2,

             'Post-Contact',           4,

             'Contact',                '-') log_type,

       decode(a.log_status,            1,

              'Pending - RO',          3,

              'Pending - Agent',       2,

              'Reviewed by RO',        4,

              'Rejected by RO',        '-') log_status,

       a.date_of_contact dateOfContact,

       to_char(a.date_of_contact, 'DD-MM-YYYY') as date_of_contact,

       to_char(a.record_creation_date, 'DD-MM-YYYY') as record_creation_date,

       to_char(case

                 when a.agent_last_update_date < a.ro_last_update_date then                  a.ro_last_update_date

                 when nvl(a.agent_last_update_date, sysdate) < sysdate then                  a.agent_last_update_date

                 else  a.ro_last_update_date

               end,'DD-MM-YYYY') as agent_last_update_date,

       b.eng_name

  FROM ross_log_info a, vagt_personal_dtls b

 

Case When

Select client_id,       surname,       given_name,       date_of_birth,       sex,       cli_pros_ind,       with_act_pol,

       case cli_pros_ind

         when 'P' then  (GET_OPT_OUT_IND(client_id, email_unsub_sig))

         else            email_unsub_sig

       end as email_opt_out,

       CHECK_PDPO_INDICATOR(client_id) as pdpo_indicator,

       case cli_pros_ind

         when 'P' then  (GET_PROSPECT_CREATE_DATE(client_id))

         else           null

       end as create_date,

       to_be_expired

  from search_cust_result

 where seq_no IN (7318)

 order by order_seq, surname, given_name, client_id desc

 

你可能感兴趣的:(case when)