TL;DR How to test if string is hex when selecting rows?
If I had a table with GUIDs where some of them are Base36 instead if hexadecimal:
ID | GUID
===|=================================
1 | CAFEBABECAFED00DB16B00B515BADA55
2 | 0123456789ABCDEFGHIJKLMNOPQRSTUV
3 | DEADBEAF4D15EA5EDEFEC8EDFEE1DEAD
I want to get all rows with GUIDs that are not exclusively hexadecimal.
For a singleton, I could try CONVERT(VARBINARY(32),[GUID],2) and see if it fails, but I can’t to that in a query. If I could query for WHERE isNaN(parseInt(GUID,16)), it would be fail-safe (while having to be applied to all rows).
Of course I could full-text search for letters following F (WHERE [GUID] LIKE '%g%' OR [GUID] LIKE '%h%' OR …), but this last resort kind of approach led me to asking this question:
How to query for (non-)hex fields only?
Just use
LIKEwith a wildcard character for a specific range: