Results 1 to 3 of 3

Thread: [RESOLVED] MS Sql Server - not filtering on Null?

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Resolved [RESOLVED] MS Sql Server - not filtering on Null?

    Hi,

    Got a weird one. I have two simple sql statements.

    Code:
    select top 10 * 
      from tablename
     where idfield is null
     
    SELECT top 10 
           pb.*
      from tablename pb
    The first returns no records.
    The second returns ten records, of which the idfield is null.

    Any ideas why MS Sql server isnt filtering correctly?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  2. #2

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: [RESOLVED] MS Sql Server - not filtering on Null?

    Found it

    The first I had pointed to a view (which got rid of nulls) the second was the table. Both had very similar names. Not ones I created, but I should have seen it.

    All sorted and makes sense now.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] MS Sql Server - not filtering on Null?

    This is an example of why it's a good idea to post the actual code if you can. Simplifying things can have its benefits but, as we're not as close to the problem, I'll wager that we'd have noticed the different names immediately, if those names had actually been posted. If a simplified example seems warranted, I'd probably recommend that in addition to the actual code, rather than instead of it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width