How do you create a nested IF/THEN statement while working with In-DB tools?
For example, I want to use the Formula In-DB tool to create a field called "Age Segment". The statement should look at my Age field and determine if it falls into these Age Segments:
Not provided, 18 and Under, 19 to 64, 65 or Older
I have tried both of the following and both returned error messages.
CASE WHEN "Age" = -1 THEN 'Not Provided' ELSE CASE WHEN "Age" < 19 THEN '18 and Under' ELSE CASE WHEN "Age" between 19 and 64 THEN '19 to 64' ELSE CASE WHEN "Age" >= 65 THEN '65 Or Older' else 'Null' end
IF "Age" = -1 THEN 'Not Provided' ELSE IF "Age" < 19 THEN '18 and Under' ELSE IF "Age" between 19 and 64 THEN '19 to 64' ELSE IF "Age" >= 65 THEN '65 Or Older' else 'Null' END IF
Any tips or tricks would be appreciated! Thanks!
Solved! Go to Solution.
Let me start by saying I am not totally sure whether it matters or not what DB you are using. I can say that if you are using a SQL Server connection then the following should work.
CASE
WHEN
"Age" = -1
THEN
'Not Provided'
WHEN
"Age" < 19
THEN
'18 and Under'
WHEN
"Age" < 65
THEN
'19 to 64'
ELSE
'65+'
END
Hope this helps,
MSalvage
Yes, that statement worked! Thank you so much :)