You are here: Re: Q on joining tables with nullable fields « MsSQL Server « IT news, forums, messages
Re: Q on joining tables with nullable fields

Posted by Ed Murphy on 11/28/24 11:59

mike wrote:

> Ok I finally got it. I still don't know why that didn't work.

Nulls are not considered equal to anything, not even other nulls.

http://en.wikipedia.org/wiki/Null_(SQL)

> But here is what I did instead and it worked.
> On the join I changed it to the following.
>
> On t1.field1=t2.field1 and (case when t1.field2 is null then '' else
> t1.field2 end)=(case when t2.field2 is null then '' else t2.field2 end)

Equivalent and shorter:

on t1.field1 = t2.field1
and coalesce(t1.field2,'') = coalesce(t2.field2,'')

coalesce() is a function that takes one or more argument and returns the
first non-null value among them, or null if they're all null.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация