home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 18,067 of 19,505   
   Hugo Kornelis to All   
   Re: Case with NULL   
   13 Jan 11 11:25:39   
   
   From: hugo@perFact.REMOVETHIS.info.INVALID   
      
   Hi Tom,   
      
   The CASE expression has two syntaxes:   
      
   1:   
   CASE   
     WHEN  THEN    
   { WHEN  THEN   ... }   
   [ ELSE  ]   
   END   
      
   2:   
   CASE    
     WHEN  THEN    
   { WHEN  THEN   ... }   
   [ ELSE  ]   
   END   
      
   The second is defined to be equivalent to the former, where each WHEN   
    is replaced by WHEN  = .   
      
   >SELECT PersonID = CASE o.ID WHEN NULL THEN o2.ID ELSE o.ID END   
      
   As a result, the expression above is valid syntax (both o.ID and NULL   
   are valid scalar expressions) - but nonsense. A comparison with NULL   
   will never evaluate to True, so this whole fragment is logically   
   equivalent to   
      SELECT o.ID   
      
   >SELECT PersonID = CASE o.ID WHEN NOT NULL THEN o2.ID ELSE o.ID END   
   and   
   >SELECT PersonID = CASE o.ID WHEN IS NOT NULL THEN o2.ID ELSE o.ID END   
      
   These are both invalid syntax, because neither NOT NULL nor IS NOT   
   NULL is a valid scalar expression.   
   --   
   Hugo Kornelis, SQL Server MVP   
   My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca