Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

Can any one help me using Case in Where Condition in Oracle or modify the below query.

using below query i am getting single row instead of condition AND vt.ticket_type NOT IN('DEFAULT','HARD')

with out using AND vt.ticket_type NOT IN('DEFAULT','HARD') condition how can i get single row.

tbl_customers
pk_customer_id	customer name	Status
1	           Peter	Active
2	           Candy	Active


tbl_tickets
pk_ticket_id	ticket_type	Meaning
1	             EASY	Tk EASY
2	          Default	Tk Default
3	            HARD	Tk HARD


tbl_tickets_customers
Pk_tkt_Customer_id	fk_customer_id	Status
1	                       1	Active
2	                       2	Active


SQL
SELECT  cvt.pk_ticket_id
          , cvt.ticket_name
          , cvt.template_file_name AS template_name
          , (CASE WHEN cc.verified ='Y' THEN
             (SELECT decode(vt.ticket_type, 'EASY', 'Tk Easy')
              FROM tbl_tickets vt
                , tbl_tickets_customers vtc
                , tbl_customers cc
             WHERE vtc.fk_ticket_id = vt.pk_ticket_id
                  AND vtc.fk_tkt_customer_id = cc.pk_customer_id
                  AND cc.pk_customer_id = 1
                  AND vt.ticket_type NOT IN('DEFAULT','HARD')
                  AND vt.active_flag = 0
                  AND cc.active_flag = 0
                  AND vtc.active_flag = 0)
             ELSE
               decode(cvt.ticket_type, 'EASY', 'Tk Easy'
                                       , 'DEFAULT', 'Tk Default'
                                       , 'HARD', 'Tk Hard')

             END)AS ticket_type

    FROM    tbl_TICKETS_CUSTOMERS cvtc
          , tbl_TICKETS cvt
          , tbl_CUSTOMERS cc
    WHERE    cvtc.fk_ticket_id = cvt.pk_ticket_id
            AND cvtc.fk_tkt_customer_id = cc.pk_customer_id
            AND cc.pk_customer_id = 11
            AND vt.ticket_type NOT IN('DEFAULT','HARD');
Posted
Updated 16-Jun-15 10:22am
v4
Comments
CHill60 12-Jun-15 8:29am    
Some sample data might help, along with some expected results. Your question is not clear enough to answer at the moment
Kapuraveni BharathKumar 15-Jun-15 5:18am    
hi,
updated with table names and data. could you help me now.
Jörgen Andersson 24-Jun-15 2:37am    
What's the expected result for this query?
John C Rayan 14-Jul-15 8:00am    
In your query you are using customer_id = 11, can you show us all the records for the customer. You are using different customer ids 1 & 11 in different places. doesn't make any sense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900