Re: NULL comparison failure in sql query
From: Dan Guzman (guzmanda_at_nospam-online.sbcglobal.net)
Date: 12/13/04
- Next message: Andrew J. Kelly: "Re: pbm with begin tran"
- Previous message: Alejandro Mesa: "RE: NULL comparison failure in sql query"
- In reply to: prabhakar: "NULL comparison failure in sql query"
- Next in thread: Aaron [SQL Server MVP]: "Re: NULL comparison failure in sql query"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 13 Dec 2004 08:15:05 -0600
You can SET ANSI_NULLS OFF so that NULL = NULL evaluates to true. See the
Books Online <tsqlref.chm::/ts_set-set_9rec.htm> for details.
However, the 'right' way to do this is to properly handle NULLs in your
query. SET ANSI_NULLS OFF is not SQL-92 compliant.
-- Hope this helps. Dan Guzman SQL Server MVP "prabhakar" <prabhakarnarvekar@msn.com> wrote in message news:e5GXttR4EHA.3376@TK2MSFTNGP12.phx.gbl... > Hi, > I want to compare 2 fields in a table considering the equality of the > fields even if NULL. > eg:- table1 has fileds name1 and name2 > field1 field2 > 1 abc abc > 2 pqr NULL > 3 NULL lmn > 4 NULL NULL > > query:- > select * from table1 where field1 = field2; > > I want this query to return 2 rows (1 and 4 )but it only returns row 1. Is > there any setting or a method by which i get the correct results > considering NULLs in comparison. (without handling the is NULL condition > in the sql query) ? > >
- Next message: Andrew J. Kelly: "Re: pbm with begin tran"
- Previous message: Alejandro Mesa: "RE: NULL comparison failure in sql query"
- In reply to: prabhakar: "NULL comparison failure in sql query"
- Next in thread: Aaron [SQL Server MVP]: "Re: NULL comparison failure in sql query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|