SQL Server Select Query with and != condition Returns Strange Result [closed]












1















I have a table in a SQL Server database with 94 rows and when I try to fetch some particular rows using



WHERE (EmpCode <> 001006)


it returns 63 rows instead of 93 rows. Please help



SELECT 
ID, EmpID, EmpCode, EmpName, Designation, [Location], DoJ, Remarks, RoleID
FROM
EmpDetails
WHERE
(EmpCode <> 001006)
ORDER BY
EmpName









share|improve this question















closed as off-topic by GSerg, Mitch Wheat, Salman A, marc_s, Martin Smith Jan 1 at 11:50



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • if EmpCode is defined as a numeric column and it does not have a unique index, then it is possible to get this result.

    – NoChance
    Jan 1 at 7:46






  • 1





    @NoChance No chance.

    – GSerg
    Jan 1 at 7:48






  • 2





    Possible duplicate of Not equal <> != operator on NULL

    – GSerg
    Jan 1 at 7:49






  • 1





    I agree with @SalmanA. Another thing to consider is the fact that numbers do not have leading zeros, so 001006 is equal to 1006 and also to 0001006.

    – Zohar Peled
    Jan 1 at 8:23






  • 1





    @iminiki stackoverflow.com/q/18015422/11683

    – GSerg
    Jan 1 at 16:31
















1















I have a table in a SQL Server database with 94 rows and when I try to fetch some particular rows using



WHERE (EmpCode <> 001006)


it returns 63 rows instead of 93 rows. Please help



SELECT 
ID, EmpID, EmpCode, EmpName, Designation, [Location], DoJ, Remarks, RoleID
FROM
EmpDetails
WHERE
(EmpCode <> 001006)
ORDER BY
EmpName









share|improve this question















closed as off-topic by GSerg, Mitch Wheat, Salman A, marc_s, Martin Smith Jan 1 at 11:50



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • if EmpCode is defined as a numeric column and it does not have a unique index, then it is possible to get this result.

    – NoChance
    Jan 1 at 7:46






  • 1





    @NoChance No chance.

    – GSerg
    Jan 1 at 7:48






  • 2





    Possible duplicate of Not equal <> != operator on NULL

    – GSerg
    Jan 1 at 7:49






  • 1





    I agree with @SalmanA. Another thing to consider is the fact that numbers do not have leading zeros, so 001006 is equal to 1006 and also to 0001006.

    – Zohar Peled
    Jan 1 at 8:23






  • 1





    @iminiki stackoverflow.com/q/18015422/11683

    – GSerg
    Jan 1 at 16:31














1












1








1








I have a table in a SQL Server database with 94 rows and when I try to fetch some particular rows using



WHERE (EmpCode <> 001006)


it returns 63 rows instead of 93 rows. Please help



SELECT 
ID, EmpID, EmpCode, EmpName, Designation, [Location], DoJ, Remarks, RoleID
FROM
EmpDetails
WHERE
(EmpCode <> 001006)
ORDER BY
EmpName









share|improve this question
















I have a table in a SQL Server database with 94 rows and when I try to fetch some particular rows using



WHERE (EmpCode <> 001006)


it returns 63 rows instead of 93 rows. Please help



SELECT 
ID, EmpID, EmpCode, EmpName, Designation, [Location], DoJ, Remarks, RoleID
FROM
EmpDetails
WHERE
(EmpCode <> 001006)
ORDER BY
EmpName






sql sql-server sql-server-2016






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 12:49









iminiki

8091020




8091020










asked Jan 1 at 7:44









Ghaffar HunzaiGhaffar Hunzai

54




54




closed as off-topic by GSerg, Mitch Wheat, Salman A, marc_s, Martin Smith Jan 1 at 11:50



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by GSerg, Mitch Wheat, Salman A, marc_s, Martin Smith Jan 1 at 11:50



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.













  • if EmpCode is defined as a numeric column and it does not have a unique index, then it is possible to get this result.

    – NoChance
    Jan 1 at 7:46






  • 1





    @NoChance No chance.

    – GSerg
    Jan 1 at 7:48






  • 2





    Possible duplicate of Not equal <> != operator on NULL

    – GSerg
    Jan 1 at 7:49






  • 1





    I agree with @SalmanA. Another thing to consider is the fact that numbers do not have leading zeros, so 001006 is equal to 1006 and also to 0001006.

    – Zohar Peled
    Jan 1 at 8:23






  • 1





    @iminiki stackoverflow.com/q/18015422/11683

    – GSerg
    Jan 1 at 16:31



















  • if EmpCode is defined as a numeric column and it does not have a unique index, then it is possible to get this result.

    – NoChance
    Jan 1 at 7:46






  • 1





    @NoChance No chance.

    – GSerg
    Jan 1 at 7:48






  • 2





    Possible duplicate of Not equal <> != operator on NULL

    – GSerg
    Jan 1 at 7:49






  • 1





    I agree with @SalmanA. Another thing to consider is the fact that numbers do not have leading zeros, so 001006 is equal to 1006 and also to 0001006.

    – Zohar Peled
    Jan 1 at 8:23






  • 1





    @iminiki stackoverflow.com/q/18015422/11683

    – GSerg
    Jan 1 at 16:31

















if EmpCode is defined as a numeric column and it does not have a unique index, then it is possible to get this result.

– NoChance
Jan 1 at 7:46





if EmpCode is defined as a numeric column and it does not have a unique index, then it is possible to get this result.

– NoChance
Jan 1 at 7:46




1




1





@NoChance No chance.

– GSerg
Jan 1 at 7:48





@NoChance No chance.

– GSerg
Jan 1 at 7:48




2




2





Possible duplicate of Not equal <> != operator on NULL

– GSerg
Jan 1 at 7:49





Possible duplicate of Not equal <> != operator on NULL

– GSerg
Jan 1 at 7:49




1




1





I agree with @SalmanA. Another thing to consider is the fact that numbers do not have leading zeros, so 001006 is equal to 1006 and also to 0001006.

– Zohar Peled
Jan 1 at 8:23





I agree with @SalmanA. Another thing to consider is the fact that numbers do not have leading zeros, so 001006 is equal to 1006 and also to 0001006.

– Zohar Peled
Jan 1 at 8:23




1




1





@iminiki stackoverflow.com/q/18015422/11683

– GSerg
Jan 1 at 16:31





@iminiki stackoverflow.com/q/18015422/11683

– GSerg
Jan 1 at 16:31












1 Answer
1






active

oldest

votes


















0














If EmpCode is a varchar datatype you should type:



WHERE (EmpCode <> '001006')


If you also want to fetch null values, you should type:



WHERE (EmpCode <> '001006') OR (EmpCode IS NULL)





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If EmpCode is a varchar datatype you should type:



    WHERE (EmpCode <> '001006')


    If you also want to fetch null values, you should type:



    WHERE (EmpCode <> '001006') OR (EmpCode IS NULL)





    share|improve this answer






























      0














      If EmpCode is a varchar datatype you should type:



      WHERE (EmpCode <> '001006')


      If you also want to fetch null values, you should type:



      WHERE (EmpCode <> '001006') OR (EmpCode IS NULL)





      share|improve this answer




























        0












        0








        0







        If EmpCode is a varchar datatype you should type:



        WHERE (EmpCode <> '001006')


        If you also want to fetch null values, you should type:



        WHERE (EmpCode <> '001006') OR (EmpCode IS NULL)





        share|improve this answer















        If EmpCode is a varchar datatype you should type:



        WHERE (EmpCode <> '001006')


        If you also want to fetch null values, you should type:



        WHERE (EmpCode <> '001006') OR (EmpCode IS NULL)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 11:44









        Amessihel

        2,3891724




        2,3891724










        answered Jan 1 at 11:35









        PeibolPeibol

        13




        13

















            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas