Can I have a formula numeric where a field is a st...
# general
c
Can I have a formula numeric where a field is a string and I cast it as a int? Basically I have a included and billed field, the included field is a free form text which holds either a number or the word all included I tried doing something like CASE WHEN with a CAST but kept running into issues
p
What do you want the result to be, and what do you want to do with the result? What number would you want to return for the "all included" case? I'd advise using a
REGEXP_REPLACE()
or similar to get rid of anything that's not a number, otherwise you're going to run into problems if the field has anything unexpected in it.
TO_NUMBER()
is what you'll be wanting to use
c
I'll try that
I have another number field in case its all included
p
Something like this:
case when {yourfield} = 'all included' then {allincludedfield} else TO_NUMBER(REGEXP_REPLACE({yourfield}, '[^0-9]+', '')) end