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,068 of 19,505   
   tshad to Lennart Jonsson   
   Re: Case with NULL   
   13 Jan 11 10:54:08   
   
   From: tfs@dslextreme.com   
      
   "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   
      
   Thanks,   
      
   Tom   
      
   >   
   >>   
   >> But not:   
   >>   
   >> SELECT PersonID = CASE o.ID WHEN NOT NULL THEN o2.ID ELSE o.ID END   
   >>   
   >> I get an error:   
   >>   
   >>        Incorrect syntax near the keyword 'NOT'.   
   >>   
   >> and   
   >>   
   >> SELECT PersonID = CASE o.ID WHEN IS NOT NULL THEN o2.ID ELSE o.ID END   
   >>   
   >   
   > There is another CASE construction (my windows vm is down so I can't   
   > verify whether it is supported by sqlserver)   
   >   
   > CASE WHEN o.ID IS NOT NULL THEN o2.ID ELSE ...   
   >   
   >   
   > /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