Snowflake
Concatenate Strings

Snowflake CONCAT: How to Concatenate Strings

What it does

CONCAT joins together two or more text strings into one. It's like when you tie together pieces of string; each piece is added to the end of the other. You can use this to combine words, sentences, or parts of text to form a new string.

Note on null values: If any of the strings you want to combine is null (which means there's nothing there), then the entire result will also be null. Think of it like a chain: if one link is missing, the whole chain breaks.

Common use cases

  • Creating a Full Name: Combine a first name and a last name into a full name.
  • Generating an Email Address: Use parts of a person's name to create an email address.
  • Address Formatting: Join street, city, and country into a full address.

How to use it

You can simply list the strings you want to join, separated by commas:


_10
SELECT CONCAT('Hello, ', 'world!') AS greeting;

This would give you: Hello, world!

Alternative using || operator

You can also use the || operator to concatenate strings, which works similarly but looks a bit different:


_10
SELECT 'Hello, ' || 'world!' AS greeting;

This does the same thing, combining the pieces into Hello, world!

Using CONCAT is handy when you want to piece together text in a database, whether it's for creating messages, formatting data, or building identifiers from parts.

Examples

Concatenating two columns

This example combines the first_name and last_name columns to form a full name.

Input

Table: hitchhikers_characters

idfirst_namelast_nametitle
1ArthurDentMr.
2FordPrefectMr.
3ZaphodBeeblebroxPresident

Snowflake SQL Query


_10
SELECT
_10
id,
_10
first_name,
_10
last_name,
_10
title,
_10
CONCAT (first_name, ' ', last_name) AS full_name
_10
FROM
_10
hitchhikers_characters;

Output

idfirst_namelast_nametitlefull_name
1ArthurDentMr.Arthur Dent
2FordPrefectMr.Ford Prefect
3ZaphodBeeblebroxPresidentZaphod Beeblebrox

Concatenating three columns

This example will concatenate the title, first_name, and last_name to create a more formal identification for each character.

Input

Table: hitchhikers_characters

idfirst_namelast_nametitle
1ArthurDentMr.
2FordPrefectMr.
3ZaphodBeeblebroxPresident

Snowflake SQL Query


_10
SELECT
_10
id,
_10
first_name,
_10
last_name,
_10
title,
_10
CONCAT (title, ' ', first_name, ' ', last_name) AS formal_name
_10
FROM
_10
hitchhikers_characters;

Output

idfirst_namelast_nametitleformal_name
1ArthurDentMr.Mr. Arthur Dent
2FordPrefectMr.Mr. Ford Prefect
3ZaphodBeeblebroxPresidentPresident Zaphod Beeblebrox
Y42 SQL completion user interface

Your AI copilot for Snowflake SQL

Write production-ready SQL with AI-based suggestions.

Get Started