Isuru Siriwardana
Isuru Siriwardana

Reputation: 545

How to get records from a table where some field's value is in camel-case

I have a table like this,

Id Value
1 ABC_DEF
31 AcdEmc
44 AbcDef
2 BAA_CC_CD
55 C_D_EE

I need a query to get the records which Value is only in camelcase (ex: AcdEmc, AbcDef etc. not ABC_DEF).

Please note that this table has only these two types of string values.

Upvotes: 0

Views: 1661

Answers (2)

Mario J Vargas
Mario J Vargas

Reputation: 1195

Based on the sample data, the following will work. I think the issue we're dealing with is checking whether the string contains underscores.

SELECT * FROM [Foo]
WHERE Value NOT LIKE '%[_]%';

See Fiddle

UPDATE: Corrected error. I forgot '_' meant "any character".

Upvotes: -2

juergen d
juergen d

Reputation: 204894

You can use UPPER() for this

select * from your_table
where upper(value) <> value COLLATE Latin1_General_CS_AS

If your default collation is case-insensitive you can force a case-sensitive collation in your where clause. Otherwise you can remove that part from your query.

Upvotes: 4

Related Questions