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,069 of 19,505   
   Lennart Jonsson to tshad   
   Re: Case with NULL   
   13 Jan 11 20:09:29   
   
   From: erik.lennart.jonsson@gmail.com   
      
   On 2011-01-13 19:54, tshad wrote:   
   > "Lennart Jonsson"  wrote in message   
   > news:igmca7$b1b$1@news.eternal-september.org...   
   >> On 2011-01-13 04:12, tshad wrote:   
   >> [...]   
   >>>   
   >>> SELECT PersonID = CASE o.ID WHEN NULL THEN o2.ID ELSE o.ID END   
   >>   
   >> I'm a bit surprised that this works. This case construction uses "=" and   
   >> nothing (including null) equals null. FWIW, this should be equal to:   
   >>   
   >> SELECT coalesce(o.ID, o2.ID)   
   >   
   > 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   
   >   
      
   I prefer coalesce over case because - IMO - it is easier to read, not to   
   mention that there is less typing involved. Other than that I don't   
   think [1] there are any differences.   
      
   [1] I have about 1 day experience with sql server, so there might be a   
   thing or two that I haven't discovered yet ;-)   
      
      
   /Lennart   
      
   --- 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