mercredi 30 mai 2018

case statements for different date columns

I'm facing issues while writing the below code in SQL developer:

 'If Trim$(psFromDate) <> "" and NOT ISNULL(psFromDate) AND Trim$(psToDate) <> "" and NOT ISNULL(psToDate) Then
select case ps_datetype
 CASE "CTA"
    wc = wc & " AND (trunc(sf_get_local (p_con.created_date,p_con.cdate_tz_code)) Between "
    wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
    wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY'))"
 'CASE "ATA" 
 CASE "VAD" 
    wc = wc & " AND trunc(sf_get_local(route_s.orgn_vsl_arvl_date,route_s.orgn_vsl_arvl_date_tz_code)) Between "
    wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
    wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY')"
 CASE "ETA"
    wc = wc & " AND TRUNC(sf_get_local(route_s.arrival_date,route_s.arrival_date_tz_code)) Between "
    wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
    wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY')"
END SELECT
'End If

I tried the below code but no luck:

Where (case when pstatustype='CTA' then (p_con.created_date Between     to_date('&1','DD-MON-YYYY:HH24:MI:SS')
                                AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
        when pstatustype='VAD' then (route_s.orgn_vsl_arvl_date Between     to_date('&1','DD-MON-YYYY:HH24:MI:SS')
                                AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
        when pstatustype='ETA'  then (route_s.arrival_date Between  to_date('&1','DD-MON-YYYY:HH24:MI:SS') 
                                AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
        else NULL end)

getting an error missing parenthesis. In then it is not taking BETWEEN operator. Please help, how i can write this code in SQL developer.

Regards, fuko

Aucun commentaire:

Enregistrer un commentaire