SQL Server Select Query with and != condition Returns Strange Result [closed]
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
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.
|
show 7 more comments
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
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, so001006
is equal to1006
and also to0001006
.
– Zohar Peled
Jan 1 at 8:23
1
@iminiki stackoverflow.com/q/18015422/11683
– GSerg
Jan 1 at 16:31
|
show 7 more comments
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
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
sql sql-server sql-server-2016
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, so001006
is equal to1006
and also to0001006
.
– Zohar Peled
Jan 1 at 8:23
1
@iminiki stackoverflow.com/q/18015422/11683
– GSerg
Jan 1 at 16:31
|
show 7 more comments
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, so001006
is equal to1006
and also to0001006
.
– 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
|
show 7 more comments
1 Answer
1
active
oldest
votes
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)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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)
add a comment |
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)
add a comment |
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)
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)
edited Jan 1 at 11:44
Amessihel
2,3891724
2,3891724
answered Jan 1 at 11:35
PeibolPeibol
13
13
add a comment |
add a comment |
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 to1006
and also to0001006
.– Zohar Peled
Jan 1 at 8:23
1
@iminiki stackoverflow.com/q/18015422/11683
– GSerg
Jan 1 at 16:31