Brettb.Com
  HOME | ABOUT ME | BIOTECHNOLOGY | ARTICLES | GALLERY | CONTACT
Search: Go
TECHNICAL ARTICLES
 ASP
 ASP.NET
 JavaScript
 Transact SQL
 Other Articles
 Software Reviews

PHOTO GALLERIES
 Canon EOS 300D Samples
 Akihabara Maids!
 More Galleries...

TRAVEL LOG
 2009: China
 2008: Tokyo
 2007: Tokyo
 2006: Hong Kong
 2005: New York City

MORE STUFF
 Search Engine Optimisation
 Build an ASP Search Engine
 My Tropical Fishtank
 Autoglass
 SQL Month Name
 SQL Get Date Today
 SQL Year Month
 Other New Stuff...

POPULAR STUFF
 Regular Expressions
 Index Server & ASP
 JavaScript Ad Rotator

Home > Articles > Transact SQL Programming Articles

Using the Transact SQL Concatenate Function

To concatenate strings together in Transact SQL, you simply need to use the "+" operator:

SELECT 'hello' + ' ' + 'world' AS 'result'

The resulting SQL results set shows hello world as the concatenated string in the result column.

MySQL and Oracle both have a Concat() function, but there isn't one in Microsoft's SQL Server. The MySQL Concat() function for concatenating strings can be used as follows:

SELECT CONCAT('hello', 'world')

Also in MySQL, strings can also be concatenated by simply putting them next to each other in a SELECT query, e.g.

SELECT 'hel' 'lo' ' ' 'world'

Often when concatenating strings with non-string data types in SQL Server it's essential to use the Convert function to convert the non-string data type into a string such as a char or varchar data type. The example below converts the current year from the date into a string:

SELECT 'this year is ' + CONVERT(CHAR(4), YEAR(GETDATE()))

Useful Links

  • The SQL Documentation Tool creates technical documentation for Microsoft SQL Server databases. A free trial version is available for download.

  Site Map | Privacy Policy

All content is 1995 - 2012