Solved

Sql query using 'like' and ignore case

Posted on 2011-09-15
7
488 Views
Last Modified: 2012-05-12
I would like to obtain results using the 'like' word but I want it to ignore the case in the results.

For example
select * from table1 where column1 like 'aBcD'
should return all the rows where column1 is ABCD, abcd, etc.

thanks,
Anu
0
Comment
Question by:Anandhi1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 39

Accepted Solution

by:
Aaron Tomosky earned 250 total points
ID: 36544452
If you are using the default Charset SQL_Latin1_General_CP1_CI_AS the ci stands for case insensitive.
0
 
LVL 1

Author Comment

by:Anandhi1
ID: 36544496
Currently my query
select * from table1 where column1 like 'ABCD%' returns only the 'ABCD' not 'abcd' .

Is it possible to do in SQL?

0
 
LVL 13

Expert Comment

by:LIONKING
ID: 36544609
You can upper everything and give it a try, something like:

select * from table1 where UPPER(column1) like UPPER('ABCD%')
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 1

Author Comment

by:Anandhi1
ID: 36544771
That worked but the query took a long time to execute. It took a minute instead of a second.

Do we have any other solution?

thanks,
Anu
0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 250 total points
ID: 36545145
That is because you wrapped the column1 with a function. Try it with COLLATE. Using aaron's Charset:

SELECT *
FROM table1 
WHERE column1 COLLATE SQL_Latin1_General_CP1_CI_AS LIKE 'ABCD%';

Open in new window

0
 

Expert Comment

by:sath350163
ID: 36546348
If column1 has index on it, doing UPPER(column1) will prevent that index from being used.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question