Concatenating a string variable and a date variable into one string in SQL Server

Posted on 2012-08-17
Medium Priority
Last Modified: 2012-08-17
Is there a way to concatenate two fields together in SQL Server using T-SQL into one string?
Question by:morinia
  • 2
LVL 66

Accepted Solution

Jim Horn earned 2000 total points
ID: 38306763
Just use the plus sign

SELECT 'goo ' + 'boo ' + 'foo'

If the fields are anything other than characters, say numbers or dates, you have to convert them to characters in order to concatenate

SELECT 'Right now it is ' + CAST(GETDATE() as varchar(max))

SELECT 'Mambo Number ' + CAST(9 as char(1))
LVL 66

Expert Comment

by:Jim Horn
ID: 38306781
Thanks for the grade.  Good luck with your project.  -Jim

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question