简体   繁体   中英

Case Sensitive search when using Excel as database

I am unable to do a case sensitive search when using Excel as a database. For eg, if the Col1 contains data like this

Data
DATA
DATa
daTA

and I perform a query like

Select * 
from [Sheet1$] 
where Col1 = 'Data'

it will retrieve all the four records.

Even using Like statement does not work.

If I give Select * from [Sheet1$] where Col1 like 'Data%' still retrieves all the four records.

The COLLATE Latin1_General_CS_AS option is only for SQL server and does not work for Excel. Can anyone tell me how to do this?

I do not need the UCASE/ UPPER/ LCASE/ LOWER functions as most of my data is in mixed case, similar to the example I have given above.

Is it possible to create a query to retrieve the data in a case -sensitive fashion ,like retrieve only Data or DATA or daTA record when I query for them?

NOTE I am using Excel 2007 .xlsx as the database and Microsoft.ACE.OLEDB.12.0 as the Provider.

Try using COLLATION (not sure if it works for excel)

Select * 
from [Sheet1$] 
where Col1 = 'Data'
COLLATE SQL_Latin1_General_CP1_CS_AS  // CS = Case Sensitive

or

Select * 
from [Sheet1$] 
where Col1 = 'Data'
COLLATE SQL_Latin1_General_CP1_CI_AS  // CI = Case Insensitive

See here for information on Windows Collations .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM