SSMS可用的UNION添加空白列SQL在Tableau失效,求替代' '的语法
Got it, let's work through this problem! The root cause here is probably that Tableau is stricter about data type consistency or how "blank" values are interpreted than SSMS. Your original ' ' (single space) might be getting treated as a non-blank value in Tableau, or there's a subtle data type mismatch between the two unioned queries. Here are several reliable alternatives to try:
1. Use NULL for explicit empty values
This is the most standard way to represent missing/blank data in SQL, and Tableau handles NULLs consistently:
SELECT [wo#], [COL2] AS "Team" FROM T1 UNION SELECT [request_external_wo_number], NULL FROM T2
- Why this works: NULL is explicitly recognized as an empty value across most data sources, including Tableau. Just make sure the
[COL2]column in T1 allows NULLs (or that Tableau can implicitly match the data type—since NULL inherits the type of the corresponding column in the first query).
2. Use an empty string ('') instead of a space
A single space (' ') might be interpreted as a valid non-blank string in Tableau. Switching to an empty string removes that ambiguity:
SELECT [wo#], [COL2] AS "Team" FROM T1 UNION SELECT [request_external_wo_number], '' FROM T2
- Why this works: Empty strings are universally understood as "no content" in SQL, and Tableau will render them as blank cells in your data preview and visualizations.
3. Explicitly cast to match data types (if type mismatch is the issue)
Sometimes SSMS does implicit data type conversion that Tableau rejects. If [COL2] is a specific string type (e.g., VARCHAR(50)), explicitly cast your blank value to match:
SELECT [wo#], [COL2] AS "Team" FROM T1 UNION SELECT [request_external_wo_number], CAST('' AS VARCHAR(50)) FROM T2
- Why this works:
UNIONrequires exact data type matching between corresponding columns. Explicit casting eliminates any ambiguity and ensures Tableau accepts the unioned result set.
Bonus Tip: Use UNION ALL if you don't need deduplication
If you don't need to remove duplicate rows between T1 and T2, replace UNION with UNION ALL. It's faster, and avoids potential issues with how Tableau handles deduplication of blank/NULL values.
Once you update your SQL, refresh your Tableau data source and check the data preview to confirm the "Team" column shows blank values as expected. If you need to convert NULLs to empty strings later in Tableau, you can use a calculated field like IFNULL([Team], '').
内容的提问来源于stack exchange,提问作者FoxyB

