Joining Variables and Strings

The concept of objects was already introduced briefly. When you are dealing with simple strings, you can easily concatenate them together using the plus (+) sign to create a new string:

PS>$last_name="Doe"PS>$first_name="John"PS>$full_name=$last_name+", "+$first_namePS>$full_nameDoe, JohnPS>

In this example, two variables containing simple strings are defined, and they are simply concatenated together with a comma character between them to create a third variable, which is then displayed to the console.

Note

This kind of concatenation works when both variables are strings. An error may be returned if the variable is of another data type.

An example is provided later with the AdventureWorks2012 ...

Get Microsoft® SQL Server 2012 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.