SQL UPPER compare

Comparing case in values in SQL when set to case-insensitive collation is a little trickier than VFP.

Where as in VFP you could do the following

SELECT fields FROM mytable WHERE UPPER(field) == field

If you want to compare case in a SQL Server database that is case insensitive, just convert to varbinary first eg:
SELECT fields FROM mytable WHERE CONVERT(varbinary, UPPER(field)) = CONVERT(varbinary, field)

Here's an example:
USE Northwind SELECT CustomerID, CompanyName, ContactName, ContactTitle, City FROM customers (NOLOCK) WHERE CONVERT(varbinary,UPPER(LEFT(CompanyName,4))) = CONVERT(varbinary,LEFT(CompanyName,4))



Last Updated: 26/11/2005