Solved

Sql query using 'like' and ignore case

Posted on 2011-09-15
7
475 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
7 Comments
 
LVL 38

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 12

Expert Comment

by:jagssidurala
ID: 36545140
0
 
LVL 59

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now