Home » SQL & PL/SQL » SQL & PL/SQL » How to use LIKE inside Where & When clauses?
How to use LIKE inside Where & When clauses? [message #217871] Mon, 05 February 2007 23:07 Go to next message
fortunethiyagu
Messages: 94
Registered: December 2006
Member

          SELECT DISTINCT    f..., 
                              cgn..., 
                              x..., 
                              cge...,
                              cgc...,
                              gxcd..., 
                              gscr...,
                              m...,
                              cs...
           FROM               g...
           WHERE              
                    CASE WHEN ( i... IS NOT NULL ) THEN 
                              ( cgn... LIKE i...||'*%' )
                    END
                AND
                   ( cge... BETWEEN '1-jan-2005' AND '1-feb-2007' ) ;


This is the code i am using to select some values which is distinct. Here the problem is LIKE clause inside where clause. its showing error. the condition is if input parameter i... is not null then i need to, match that field with cgn....

please help me...

[Updated on: Fri, 01 June 2007 17:53] by Moderator

Report message to a moderator

Re: How to use LIKE inside Where & When clauses? [message #217884 is a reply to message #217871] Mon, 05 February 2007 23:54 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
You will get the expected result by using OR:
          SELECT DISTINCT    f..., 
                              cgn..., 
                              x..., 
                              cge...,
                              cgc...,
                              gxcd..., 
                              gscr...,
                              m...,
                              cs...
           FROM               g...
           WHERE              
                   (( i... IS NULL ) OR ( cgn... LIKE i...||'*%' ))
                AND
                   ( cge BETWEEN '1-jan-2005' AND '1-feb-2007' ) ;

[Updated on: Fri, 01 June 2007 18:03] by Moderator

Report message to a moderator

Re: How to use LIKE inside Where & When clauses? [message #217906 is a reply to message #217884] Tue, 06 February 2007 01:11 Go to previous message
fortunethiyagu
Messages: 94
Registered: December 2006
Member

Thanks yaar..

it works...cool...
Previous Topic: Query with multiple inner rows
Next Topic: Need to know how this query works
Goto Forum:
  


Current Time: Mon Dec 05 02:48:44 CST 2016

Total time taken to generate the page: 0.12688 seconds