Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Thomas, I think the problem is that the data type of the field is char(6). This means that the field always has 6 characters (see last paragraph). However, when you are setting things up in .NET, it is a string, which won't have the extra characters. I.e.
If you provide 'B-M' from .NET, it won't match the value in the database, which is 'B-M ' (note extra spaces).
If the values are unique enough, you can just switch to a like statement:
WHERE adresse Like(@pAdresse + '%')
This won't work if you could have values like 'BAL' and 'BALM', because 'BAL' would incorrectly match 'BALM' also.
The next option would be to manipulate the SQL field by trimming it:
WHERE adresse = RTRIM(@pAdresse)
You could also try padding the .NET strings, but that would be harder than just trimming the db value.
When I did a test in SQL Server 2005, you original query worked. I.e. SQL Server 2005 doesn't include the extra spaces to ensure that the string is 6 characters. However, I think SQL Server 2000 does include the extra spaces, because I know I'd had to deal with this before.
|