Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Sun, 23 Apr 2006 @ 19:53:51 GMT


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


Subj:   Re: Help needed for writing SQL
 
From:   Dieter Noeth

Naveen Kambhoji wrote:

  Now I Came to know from users that they can also denote NULL as 'E' (Empty). In plain english my requirements are  


  If Name = 'A' and (Value IS NOT NULL OR VALUE <> 'E' ) Then VALUE else get the value of the name 'B'. Basically I need to select name value pairs for each member in a web based application.  


Just put it into the CASE:

     SELECT
         MemID,
         COALESCE(MAX(CASE WHEN Name = 'A' AND VALUE <> 'E' THEN Name END),
                  MAX(CASE WHEN Name = 'B' THEN Name END)
                 ) AS Name,
         COALESCE(MAX(CASE WHEN Name = 'A' AND VALUE <> 'E' THEN Value END),
                  MAX(CASE WHEN Name = 'B' THEN Value END)
                 ) AS Value
     FROM TheTable t1
     GROUP BY 1;

Similar for Frank's query...

Dieter



     
  <Prev Next>   <<First <Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023