• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1980
  • Last Modified:

Upper and lowercase in a query

I have a table where the users may enter names in upper and/or lowercase. I could have, for example, NAME1 equal to 'ABEL MARY' and NAME2 equal to 'deBlank John'. The query in the code does the following:

select count(*) from table
where upper(name) >= :NAME1
and upper(name) <= :NAME2

but that is obviously resulting in a restricted data set and it does not covers the lowercase names. Considering that the user may type either NAME1 and/or NAME2 with upper or lowercases, how would it be the best way to cover all the data range in the table?

1 Solution
Nick UpsonPrincipal Operations EngineerCommented:
the usual way is to add an additional field to the table, called, say UPPERNAME

populate it with triggers that contain


then always do your search against UPPERNAME

there are other ways, such as using specific character sets and collations but this is the simplest

this way the database doesn't need to convert every record to uppercase everytime the query is run
Gary BenadeCommented:
select count(*) from table
where upper(name) >= upper(:NAME1)
and upper(name) <= upper(:NAME2)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now