Normally SQL Server is installed to be case insensitive, yet you need to perform a case sensitive search. Thus when trying to do a normal string comparison you run into problems.
if ‘foo’ = ‘FOO’
print ‘strings match’
else
print ‘strings are different’
Will tell you the strings match, yet they clearly aren’t the same if you’re talking case. There are least two ways in SQL Server. First, you can convert them to binary values:
if convert(varbinary,’foo’) = convert(varbinary,’FOO’)
print ‘strings match’
else
print ‘strings are different’
Or if you’re on SQL Server 2000 you can change the collation to be case-sensitive:
if ‘foo’ collate Latin1_General_CS_AI = ‘FOO’ collate Latin1_General_CS_AI
print ‘strings match’
else
print ‘strings are different’
So there you go. Happy string matching!