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,074 of 19,505   
   Gene Wirchenko to esquel@sommarskog.se   
   Re: Case with NULL   
   14 Jan 11 12:07:32   
   
   From: genew@ocis.net   
      
   On Thu, 13 Jan 2011 22:49:06 +0100, Erland Sommarskog   
    wrote:   
      
   >tshad (tfs@dslextreme.com) writes:   
   >> Is one better than the other?   
   >>   
   >> SELECT PersonID = coalesce(o.ID, o2.ID)   
   >>   
   >> or   
   >>   
   >> SELECT PersonID = CASE WHEN o.ID IS NULL THEN o2.ID ELSE o.ID END   
   >   
   >As Lennart says, the former is shorter to type. The algebrizer   
   >rewrites coalesce to a CASE expression, so they are very equivalent.   
   >   
   >But you could claim that CASE is better, because it is more honest.   
                                                                ^^^^^^   
        Not the adjective I would have picked.  Is there a technical   
   difference that matters?   
      
   >Say that you write:   
   >   
   >  coalesce((SELECT ....), 4711)   
   >   
   >Looks good. But this is the true story:   
   >   
   >   CASE WHEN (SELECT ...) IS NOT NULL THEN (SELECT ...) ELSE 4711 END   
   >   
   >Personally, I use coalesce all the time.   
      
        Get the computer to do your lying for you?     
      
   Sincerely,   
      
   Gene Wirchenko   
      
   --- 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