How to select strings in UUID format + case sensitive wildcards

How can I select only strings in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX where X is any number or any UPPERcase (not lowercase) character?

Example dataset:

ed54cb09-b402-4551-912d-b8e0fec69d9e --I do not want to select this one
00029B19-80CC-4FF8-BE11-BDB55FC7FC2A --I do want to select this one

Some are all-caps, some are not, and this is a varchar field. I want to select only these all-caps UUIDs, excluding the rest.

Currently I’m using the _ wildcard to look for the basic UUID format, but looks like UPPER doesn’t apply to the _ wildcard. Ex.:

SELECT mycolumn
FROM mytable t
WHERE  t.mycolumn like UPPER('________-____-____-____-____________') COLLATE SQL_Latin1_Gene

You May Also Like

More From Author