• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 622
  • Last Modified:

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

Is there a way to concatenate two fields together in SQL Server using T-SQL into one string?
0
morinia
Asked:
morinia
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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))
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now