Sometimes, comparing 2 strings can be a bit tricky in MS SQL Server. For example, if there is a field of name as varchar(n), containing the value of "Microsoft", it is actually treated as "Microsoft " (fill the rest of field with spaces). Therefore using = always return wrong answer. Using LIKE however, return those strings which contains word Microsoft which is not the desired answer. The solution is to use PATTERN MATCHING as follow:
SELECT "Microsoft " = "Microsoft[ ]%"
[ ]% represents the spaces
SELECT "Microsoft " = "Microsoft[ ]%"
[ ]% represents the spaces
No comments:
Post a Comment