Aeonstrife
Aeonstrife

Reputation: 673

Matching substrings SQL Server

I have a table with a column with big strings. I want to search through these strings and see if there are 4 consecutive upper case characters. Is there a way of doing this? I'm not too experienced in the substring methods of SQL.

Upvotes: 0

Views: 223

Answers (1)

gbn
gbn

Reputation: 432210

Looking for 4 chars inside a string is a classic LIKE in most SQL dialects.

To force upper case, you need to coerce the collation too with the COLLATE clause. The "CS" makes your column case sensitive

...
WHERE
   MyColumn COLLATE Latin1_General_BIN LIKE '%ABCD%'

Edit: for any 4 upper case characters

...
WHERE
   MyColumn COLLATE Latin1_General_BIN LIKE '%[A-Z][A-Z][A-Z][A-Z]%'

Edit: with Latin1_General_BIN

Upvotes: 3

Related Questions