0

I'm getting an error with the following SQL query

SELECT b.mo_id,
        b.ot_id, (select ot_name from object_type where ot_id = b.ot_id
        )ot_name,
        a.obj_id, b.pt_id, b.pt_name, b.data_type, a.prop_value1,
        CASE
        WHEN b.data_type = '2'
        THEN (SELECT code_name FROM site_code WHERE group_seq = b.group_seq AND code_seq = a.prop_value1)
        WHEN b.data_type = '3' THEN TO_CHAR(a.prop_value1,'999,999,999,999,999')
        WHEN b.data_type = '5' AND a.prop_value1 is not null THEN TO_CHAR(to_date(a.prop_value1,'YYYYMMDD'),'YYYY/MM/DD')
        WHEN b.data_type = '6' THEN TO_CHAR(a.prop_value1,'999,999,999,999,999')
        WHEN b.pt_id = '12003' THEN CONCAT_WS('', SUBSTR(a.prop_value1,0,18) , 
        case when length(a.prop_value1) > 18 then '...' else '' end  ELSE a.prop_value1 
        END prop_value1_view, b.pt_order, b.default_yn, b.list_yn, b.align, b.group_seqFROM 
        (SELECT * FROM property_type WHERE ot_id = #otId# AND list_yn = '1') b LEFT OUTER JOIN
        
        (SELECT * from property where ot_id = #otId# AND obj_id = '') a ON a.ot_id = b.ot_id AND a.pt_id = b.pt_id ORDER BY b.pt_order
                                    
1
  • A case expression only supposed one else clause. I'm voting to close as a typeo. Commented Aug 3, 2021 at 11:50

1 Answer 1

1

This case statement is not legitimate:

case when length(a.prop_value1) > 18 then '...' else '' end  ELSE a.prop_value1 

I am not exactly sure what is the objective, but here are options that will fix it.

  1. Either this is part of the ongoing case statement (i.e. the previous one) -- In this case, you don't need to write case again. It will continue from 'when length(a.prop_value1) > 18 then '...' else '' end ELSE a.prop_value1 '

  2. If you want this to be a separate case statement altogether, you need to end the previous case statement by writing END before this case block begins (not to forget writing else part if you intend to.)

  3. There are 2 else statements one after the other, that's again invalid either one of the else is part of the previous or following block.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.