sql - Account for NULL and Blank as being different in comparison (issue caused by ISNULL function) -


i'm looking best practices here far checking equality fields may null or blank. example, if i'm doing comparison such

a.field01 != b.field01 in clause, know need account nulls if ansi_nulls on, such as: isnull(a.field01,'') != isnull(b.field01,'') in order cases 1 of fields null , other not. however, since database i'm working has blank fields in addition nulls (ugh), i'd comparison distinguishes between null , blank, intend use in update script update accordingly (and set destination column null). above comparison, if 1 field blank ('') , other null, row not evaluated being different. best practice here make suret following results returned:

a.field01 (null) != b.field01 (blank) a.field01 (blank) != b.field01 (blank) a.field01 (null) != b.field01 (non-null / blank) a.field01 (non-null / blank) != b.field01 (null) 

sorry if of confusing or poorly communicated. let me know , i'll try explain better if that's case!

i'm not sure confusion lies. if want not-equals between 2 fields, should do:

a.field01 <> b.field01 

if either (or both) values null, evaluates null treated false. seems logic want.

if want blanks treated null (which on closer reading seems desire), then:

nullif(a.field01, '') <> nullif(b.filed01, '') 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -