Geeks on Campus

anything, everything, geeky.

A better CONCAT?

Posted by jeggent on May 19, 2022

In past posts (example, another, yet another) I’ve demonstrated using the CONCAT function to combine strings/fields. However CONCAT is limited to two arguments and I have often had to string multiple CONCATs together to accomplish a desired output. While the resulting expression looks kind of cool, it isn’t easy to write. I have just found a better way.

Instead of using the CONCAT function, you can just use the concatenation operator “||”. So to get an output like F23OTT (I), what would have been:

CONCAT(A.CHKLST_ITEM_CD, CONCAT( ‘ (‘, CONCAT(A.ITEM_STATUS, ‘)’)))

Can now be:

C.CHKLST_ITEM_CD || ‘ (‘ || C.ITEM_STATUS || ‘)’

That may not look hugely different, but it is much easier to write without all of the additional commas and parentheses.

That’s it. That’s the post. Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *