# Concatenate

Concatenation allows you to combine two or more strings (text fields or user-defined text) into a single value. This is useful for generating new fields, e.g. `Full Name` from `First Name` & `Last Name`, or creating combined values to act as a unique lookup key.

Some tools like Excel, OrgVue and Python have two types of concatenation: `a + b` style syntax and `concat(a,b)` style syntax. Both options are listed below.

NB. Using the `join()` method in OrgVue you can specify a delimiter to use between each string to be concatenated. In all other methods, if you want to have a delimiter between combined strings you need to add it separately as many times as needed.

## Excel

In Excel you have two options for combining strings: \
&#x20;Option 1: `&` is the quickest if you only have 2 values to combine \
&#x20;\=‹value1›&‹value2›

```
=A1&A2
```

Option 2: `CONCATENATE()` is better for long chains \
&#x20;\=\~CONCATENATE!\~(‹value1›, ‹value2›, ‹value›)

```
=CONCATENATE(A1," ",C1)
```

## Tableau

‹string1› + ‹string2›

```
[First Name] + [Last Name]
```

NB. Both arguments must be strings. To convert a different data type to a string, use \~STR!\~(‹field›). Go to [General > Convert Types](https://concentra-analytics.gitbooks.io/writing-calculations/content/general/convert_type.html) for more information.

## Alteryx

‹string1› + ‹string2›

```
[First Name] + [Last Name]
```

NB. Both arguments must be strings. To convert a different data type to a string, use \~TOSTRING!\~(‹field›) or the **Select** tool (in the **Preparation** palette). Go to [General > Convert Types](https://concentra-analytics.gitbooks.io/writing-calculations/content/general/convert_type.html) for more information.

## OrgVue

In OrgVue you have three options for combining strings: <br>

Option 1: `format()` is the simplest and most efficient \
&#x20;node.\~format!\~('{‹string1›}«delimiter»{‹string2›}')

```
node.format('{firstname} {lastname}')
```

NB. Fields in the dataset (`firstname` and `lastname` in this example) are referenced inside curly braces `{}`. If you want to join a value of the node with user-specified text, don't surround that string with the curly braces, e.g. `node.format('My name is {firstname}')`.

Option 2: `join()` is more flexible because it allows you to include conditional statements and references to a node's relatives \
&#x20;\[‹string1›,‹string2›].\~join!\~("«delimiter»")

```
[node.role, node.grade > 4 ? " (Senior Mgr)" : ""].join("")
```

Option 3: `concat()` is the most long-winded \
&#x20;‹string1›.value.\~concat!\~(«delimiter»).\~concat!\~(‹string2›)

```
node.firstname.value.concat(" ").concat(node.lastname)
```

## tSQL

In SQL you have two main options for combining strings: <br>

Option 1: `+` is the quickest if you only have a few values to combine \
&#x20;‹field1› +' '+ ‹field2› \
&#x20;‹field1› +' '+ ‹string1›

```
SELECT FirstName+' '+LastName AS FullName
FROM EmployeesData
-- OR
'OLD'+RecordID
```

Option 2: `CONCAT()` is better for long chains \
&#x20;\~CONCAT!\~(‹string1›, ‹string2›«, ‹stringN»)

```
SELECT CONCAT(Address, City, PostCode) AS Location 
FROM EmployeesData
```

NB.:

* CONCAT is only available with SQL2012 onwards
* When concatenating, both ‹fields› (or ‹field› and ‹string›) must be of the same data type.

## Python&#x20;

In Python you have two main options for combining strings: \
&#x20;Option 1: `+` is the quickest if you only have a few values to combine \
&#x20;‹string1› + ‹string2›

```
firstName + lastName
```

Option 2: `join()` \
&#x20;"".\~join!\~(‹string1›, ‹string2›)

```
"".join([firstName,  lastName])
# OR
"".join(["John", " Cleese"])
# Returns "John Cleese"
```

NB.:

* The above example assumes variables have been declared for `firstName` and `lastName`. For more information, go to [General > Variables](https://orgvue.gitbooks.io/formula-translator/content/general/variables.html).&#x20;
* To join the same string together multiple times, you can use the mathematical operator `*`, e.g. ‹string1›\*3 returns ‹string1string1string1›:

```
location = "Camelot"

location*3 
# Returns "CamelotCamelotCamelot"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://concentra-analytics.gitbook.io/working-with-data/strings/concatenate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
