[s] + [t] joins two strings, and any null part makes the whole result null. DuckDB's || behaves the same. concat() does not: it skips null parts and still returns text.
Updated · Checked on the xmetric engine
What is the syntax?
string + string
string
strings or string fields; numbers must go through STR() first.
Returns the joined string. Null if any part is null.
What does it return, and what is the SQL?
Each example runs on the same 8 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
How do I join s and t with a separator?
Tableau
[s]+' / '+[t]
SQL (DuckDB)
SELECT s ||' / '|| t AS result
FROM input
ORDERBY id
Rows 5 and 6 miss one side, so the result is null.
s
t
Result
West
west
West / west
East
North
East / North
North
North
North / North
south
East
south / East
East
null
West
null
East
South
East / South
east
east
east / east
✓ The Tableau formula and the SQL return the same 8 rows.
How do I put a number in a label?
Tableau
'#'+STR([a])
SQL (DuckDB)
SELECT'#'||CAST (a AS VARCHAR) AS result
FROM input
ORDERBY id
#7, #-7, and null where a is missing.
a
Result
7
#7
−7
#-7
2
#2
9
#9
5
#5
null
1
#1
−3
#-3
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does concat() return text for rows 5 and 6?
concat() treats null as an empty string. Tableau returns null when any part is missing, so labels and counts differ.
Tableau
[s]+' / '+[t]
Tempting SQL
SELECTconcat(s, ' / ', t) AS result
FROM input
ORDERBY id
SQL that matches
SELECT s ||' / '|| t AS result
FROM input
ORDERBY id
s
t
Tableau
Tempting SQL
SQL that matches
West
west
West / west
West / west
West / west
East
North
East / North
East / North
East / North
North
North
North / North
North / North
North / North
south
East
south / East
south / East
south / East
East
null
/ East
null
West
null
West /
null
East
South
East / South
East / South
East / South
east
east
east / east
east / east
east / east
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
How do I write it in Snowflake or BigQuery?
The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.
Snowflake
SELECT s ||' / '|| t AS result
FROM input
ORDERBY id