Wow, some quite complicated solutions out there...
As you have noticed, SQL Server handles data comparison according to the
ANSI standard. When comparing two string values of different size, the
smaller one will be padded with spaces until they are equal in size.
Then they are compared.
So the query "WHERE ID = '3020'" will also include the rows where ID =
'3020 ', and the query "WHERE ID = '3020 '" will also include rows where
ID = '3020'.
However, LIKE works differently. LIKE will not add spaces before
comparing. So the query "WHERE ID LIKE '3020 '" will not return rows
where ID = '3020', but only the exact match.
So for your situation, IMO this is by far the easiest solution. Please
note, that this will only work properly if your literal (or variable)
does not contain wildcards such as "%", "_", "[", etc. So the short
answer is:
select SOM_SalesORderID, *
from SalesOrder
where SOM_SalesORderID like '3020 '
--
Gert-Jan