Duplicate data in two columns when a where clause is added

  • I wrote a query where I want to filter between 2 values. 
    First I wrote a simple query:

    SELECT
    [Ken_Seq_Nbr]
      ,[Ken_Date_Time]
      ,[Ken_Game]
      ,[Ken_N01]
      ,[Ken_N02]
      ,[Ken_N03]
      ,[Ken_N04]
      ,[Ken_N05]
    FROM [Keno].[dbo].[Ken_Raw_Data]

     order by ken_seq_nbr desc

    and get this result:


    As you can see, columns Ken_N04 and Ken_N05 are different as they always should be.  There should never be any duplicated data in a row.
    so then I added ampervariables and a where clause selecting data between the apmpervariables as below:

    declare @seq as int
    declare @seqa as int
    set @seq= 400
    set @seqa = 600
    SELECT [Ken_Seq_Nbr]
      ,[Ken_Date_Time]
      ,[Ken_Game]
      ,[Ken_N01]
      ,[Ken_N02]
      ,[Ken_N03]
      ,[Ken_N04]
      ,[Ken_N05]
    FROM [Keno].[dbo].[Ken_Raw_data]
     where convert(int,Ken_seq_nbr) between @seq and @seqa
     order by ken_seq_nbr desc


    and I get this output:

    as you can see, Ken-N04 and Ken_N05 are duplicates. 
    It only happens where I add the between clause. 
    (I checked and it also duplicates when I do a  where @seq = Ken_Seq_Nbr as well.
    Does anybody have an answer?

  • What happens if you run this 
    SELECT
    [Ken_Seq_Nbr]
    ,[Ken_Date_Time]
    ,[Ken_Game]
    ,[Ken_N01]
    ,[Ken_N02]
    ,[Ken_N03]
    ,[Ken_N04]
    ,[Ken_N05]
    FROM [Keno].[dbo].[Ken_Raw_Data]
    WHERE [Ken_N04] = [Ken_N05]

  • Thank you for your help. I really thought that there was no chance at all that I was inserting duplicate numbers.  From row 2 to row 999, there are duplicates. 
     It sucks,  but one of the changes I am going to make is to have the sequence number an integer and not a varchar.  Originally, I made it a varchar so it would line up in a textboxes
    in visual basic, but now realize that it can be an integer with no problem.

    Thanks again.  I didn't check the data since I was so confident in it's integrity.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply