I have a char(15) NOT NULL
column. I need to see if it is empty or contains all zeros. I can obviously do= '000000000000000'
But is there a way using LIKE
so its not hard coded to 15? I don't see why the [^0]
below doesn't match all zeros.
CASE WHEN LTRIM(RTRIM(IL.ItemNumber)) = '' THEN 1 ELSE 0 END IsEmpty
CASE WHEN LTRIM(RTRIM(IL.ItemNumber)) <> '' AND LTRIM(RTRIM(IL.ItemNumber)) NOT LIKE '[^0]' THEN 1 ELSE 0 END IsZeros
I'm basically trying to validate the column. Trimming works for empty, but maybe there is a much cleaner/flexible way to accomplish both of these validations? Thanks!
[^0]
matches only a single character, and this is because of the definition of the patterns used withLIKE
.