On a saved search, is it possible to concatenate f...
# general
s
On a saved search, is it possible to concatenate fields conditionally. I have tried CASE WHEN 'X'='X' THEN 'A' ELSE '' END || CASE WHEN 'Y'='Y' THEN 'B' ELSE '' END Hoping to get one of 'AB', 'A', 'B', or '' But always get error in expression. Has anyone done anything like this?
c
You can do something like this
Copy code
CASE WHEN 'A' IS NOT NULL AND 'B' IS NOT NULL THEN 'A'||'B' WHEN 'A' IS NULL AND 'B' IS NOT NULL THEN 'B' WHEN 'B' IS NULL AND 'A' IS NOT NULL THEN 'A' ELSE NULL END
I assume 'A' and 'B' are fields or nested formulas
s
X and Y are fields, A and B are the results that I want concatenated. I was hoping to avoid a single Case statement as there are currently 3 fields that I need to concatenate on contigency but that may grow and the complexity of the case statement would grow exponentially if I did it within one case statement.
j
I also got your function working using the CONCAT function. Example: CONCAT(CASE WHEN {type}='Journal' THEN 'A' ELSE '' END,CASE WHEN {postingperiod}='Jan 2023' THEN 'B' ELSE '' END)
c
You can use LISTAGG(CASE WHEN {a thing meets my condition} THEN 'Hello World' ELSE NULL END, ', ') Listagg only works in summary results though 🙂
ah, forget my LISTAGG suggestion since you are evaluating different fields.. womp
j
actually it looks like your original formula using the || operator worked too. Are you sure you just didn't mistype something (maybe especially the fields you're trying to reference)?
s
Thank you both. Got it to work. Not sure if I had something mis-typed or if it was because I was working with a checkbox, datetime, and list field, but I did a TO_CHAR on them all before doing my concat and possibly corrected some other missing parens or something but it is working.
✅ 2