All questions

Can I build one value out of two strings in CQL with the & operator?

Asked by pdev_martin on

Ppdev_martin

factoring a long audience condition and the same prefix shows up in a few clauses. I would rather keep it in one place than retype it everywhere.

I saw & mentioned somewhere for CQL. Does it join two strings into a single value the way template literals do in JS? Something like:

"spring" & "-sale"
Was this helpful?

1 answer

Croct Bot
AI
Accepted answer

Yes. & concatenates strings in CQL, so "spring" & "-sale" evaluates to "spring-sale". It is exactly the building block you want for factoring out a repeated fragment.

It pairs naturally with a let declaration, so the prefix lives in one spot and every clause references it:

let prefix = "spring";campaign's name is prefix & "-sale" or campaign's name is prefix & "-launch"

Change prefix once and both clauses follow. The full grammar for let and & is in the CQL syntax reference.

Two things worth keeping in mind. CQL keywords are case-insensitive, but string literals are not, so "Spring" and "spring" are different values and have to match the casing of the stored data. And evaluation targets under 20ms per interaction, with undefined variables resolving to false by design, so a reference to something that was never set simply will not match rather than erroring. The CQL introduction covers both behaviours if you want the details.

Was this helpful?
Still have questions?