0

These queries all return the same result of one record

SELECT COUNT([partnr]) 
FROM [dbo].[tblPart] 
WHERE [partnr] = 'SIE.3RV1021-1EA10, In=2,8-4 A SHS UL   '

SELECT COUNT([partnr]) 
FROM [dbo].[tblPart] 
WHERE [partnr] = 'SIE.3RV1021-1EA10, In=2,8-4 A SHS UL      '

SELECT COUNT([partnr]) 
FROM [dbo].[tblPart] 
WHERE [partnr] = 'SIE.3RV1021-1EA10, In=2,8-4 A SHS UL            '

The result should be zero (0).

Only with this one it should be one.

SELECT COUNT([partnr]) 
FROM [dbo].[tblPart] 
WHERE [partnr] = 'SIE.3RV1021-1EA10, In=2,8-4 A SHS UL'

What am I doing wrong or do I need to change?

EDIT:

Thank you Bhasyakarulu Kottakota. Solution:

SELECT COUNT([partnr]) 
FROM [dbo].[tblPart] 
WHERE [partnr] LIKE 'SIE.3RV1021-1EA10, In=2,8-4 A SHS UL   '
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
raiserle
  • 677
  • 8
  • 31
  • You can refer to this article about that exact problem: https://support.microsoft.com/en-us/help/316626/inf-how-sql-server-compares-strings-with-trailing-spaces – BillRuhl May 07 '20 at 16:18
  • 1
    Please use "like" instead of "=". Since this is the default behavior of SQL Server (http://support.microsoft.com/kb/316626). – Bhasyakarulu Kottakota May 07 '20 at 16:20

0 Answers0