Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Atlanta, Georgia, USA
    Posts
    274
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    I'm struggling with something I thoought would be easy.
    I have a table with 3 columns
    ID, Selected, PreviousSelected

    The Selected and PreviousSelected would contain the value "Yes"
    Code:
    ID Selected PreviousSelected
    1   Yes	 Yes
    2		   Yes
    3   Yes
    4   Yes
    What I want to do is compare the two columns to see if there is a difference between Selected and PreviousSelected.
    Basically return a count of the differences. The above would show 3 differences.

    I tried using <>
    SELECT tblBranch.BranchID, tblBranch.Selected
    FROM tblBranch
    WHERE (((tblBranch.Selected)<>[tblBranch].[PreviousSelected]));
    Also tried not in:
    SELECT tblBranch.Selected
    FROM tblBranch
    WHERE (((tblBranch.Selected) Not In (select distinct [tblBranch].[PreviousSelected] from [tblBranch])));
    I don't know what I'm doing wrong but would appreciate assistance.
    Thanks,
    Scott

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You have to treat null (blank) values separately. Try

    SELECT BranchID, Selected, PreviousSelected
    FROM tblBranch
    WHERE (Selected<>PreviousSelected) Or (Selected Is Not Null And PreviousSelected Is Null) Or (Selected Is Null And PreviousSelected Is Not Null)

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Atlanta, Georgia, USA
    Posts
    274
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='786750' date='29-Jul-2009 16:19']You have to treat null (blank) values separately. Try

    SELECT BranchID, Selected, PreviousSelected
    FROM tblBranch
    WHERE (Selected<>PreviousSelected) Or (Selected Is Not Null And PreviousSelected Is Null) Or (Selected Is Null And PreviousSelected Is Not Null)[/quote]

    Thanks Hans that did the trick
    Scott

Posting Permissions

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